Skip to content

Conversation

@andreaslhjulstad
Copy link
Collaborator

This PR extends the ScalarEvolution implementation by adding support for computing recurrences for GetElementPtr operations. It does this by adding a few new cases to the GetOrCreateSCEVForOutput() method, particularly for GetElementPtr, Load, IOBarrier and SExt operations. The SCEV for the GetElementPtr operation is computed recursively to support an arbitrary number of indexes, and supports both array and struct GEPs. This PR also adds two simple tests for the two types of GEPs.

Since the value of a GEP is not directly tied to the update of an induction variable (passes through a load from memory), some changes were needed in the way recurrences are computed. Particularly, we now compute recurrences for all valid SCEVs as opposed to computing the recurrences for just the loop variables. By valid we mean that the dependencies for the RVSDG output the SCEV corresponds to passes the three requirements. These being:

  • No more than one self-dependency in the dependency graph (indicates a self-dependent variable)
  • No cyclic dependencies (A depends on B and B depends on A)
  • No dependencies via multiplication (results in a geometric update sequence, which we treat as an invalid induction variable)

This change means that we end up with a larger amount of chain recurrences at the end of the analysis, some of which can be seen as "junk" or "noise". For the analysis itself this makes no difference, however for measuring the results, we should probably filter most of these out.

This approach seems like the best choice moving forward, and is necessary for supporting getelementptr instructions.

Also updates the tests accordingly. In particular, we no longer care about the size of the resulting chrec map in the tests, as a lot more outputs now have computed chrecs than only the loop variables. We still check that the loop variables are in the map in the tests, so no behavior has changed there.
@andreaslhjulstad andreaslhjulstad enabled auto-merge (squash) February 9, 2026 12:03
Copy link
Owner

@phate phate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some more comments to the map accessor methods.

@andreaslhjulstad andreaslhjulstad merged commit 3c74883 into phate:master Feb 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants