Skip to content

C++: Support reasoning about whether a phi node overwrites the entire buffer#21836

Draft
MathiasVP wants to merge 7 commits into
github:mainfrom
MathiasVP:uncertain-def-more-complete
Draft

C++: Support reasoning about whether a phi node overwrites the entire buffer#21836
MathiasVP wants to merge 7 commits into
github:mainfrom
MathiasVP:uncertain-def-more-complete

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

@MathiasVP MathiasVP commented May 12, 2026

There isn't a super great motivation for this work other than the fact that had most of it lying around in a local branch.

These changes are most likely necessary if we ever want to switch the instantiation of the shared range analysis library over from the sound IR-based SSA to dataflow-based SSA.

In order to model flow through something like:

p[i] = source();
p[j] = 0;
sink(p[k]);

(without knowing the concrete values for i, j, and k) we model the write to p[i] and p[j] as "uncertain" writes. That is, the write to the underlying SSA variable isn't overwritten. So whatever value was previously tracked by SSA is not killed by the SSA definition.

For this PR it's not super important how we conclude which definitions overwrite the entire buffer.

On main we currently consider any definition from a PhiNode to be an uncertain definition. This PR changes this so that we consider a PhiNode to be a certain definition whenever its inputs are all certain definitions.

There are some technical things that make this slightly more complicated than what you would expect: Since a PhNode can be its own input we need recursion over a graph with cycles, and because of QL's least fixed-point semantics we don't get the right result when doing recursion over a graph with cycles. So we instead recurse over a graph whose nodes are the the recursive PhiNodes.

As always, recursion through forall is also dangerous and should ideally be rewritten using explicit recursion over integers to reduce the risk of performance problems. However, I'll delay that until we actually see a performance problem on a database.

(I expect this work to be necessary for switching the instantiation of the shared range analysis library over to dataflow-based SSA because I expect the relevant SSA variables for range analysis to be those for which any SSA definition is a certain SSA definition.)

@github-actions github-actions Bot added the C++ label May 12, 2026
@MathiasVP MathiasVP added no-change-note-required This PR does not need a change note and removed C++ labels May 12, 2026
@github-actions github-actions Bot added the C++ label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant