You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
v12 is our loop's basic induction variable. We know that v201 = mul v12, u32 2 is a derived induction variable. Which means that v201 is a linear function of a basic induction variable v = c * i + d, where c and d are loop invariants. We should be able to transform our loop to only perform only an addition in the loop and move the multiplication out of the loop.
We know that the upper bound of our loop is 10. Knowing that our induction variable is v201 = mul v12, u32 2 we should be able to rewrite our loop as such:
After propagating the new instructions following induction variable elimination, let's take a look at the remaining instructions in b29 from above. We can see how this largely simplifies array indexing.
Problem
If we have some loop:
When
a
contains composite types, we currently will generate extra operations for array indexing.An example SSA loop body:
v12
is our loop's basic induction variable. We know thatv201 = mul v12, u32 2
is a derived induction variable. Which means thatv201
is a linear function of a basic induction variablev = c * i + d
, wherec
andd
are loop invariants. We should be able to transform our loop to only perform only an addition in the loop and move the multiplication out of the loop.Happy Case
From the loop header in the snippet above:
We know that the upper bound of our loop is 10. Knowing that our induction variable is
v201 = mul v12, u32 2
we should be able to rewrite our loop as such:After propagating the new instructions following induction variable elimination, let's take a look at the remaining instructions in
b29
from above. We can see how this largely simplifies array indexing.For more info these slides from CMU are very helpful:
https://www.cs.cmu.edu/afs/cs/academic/class/15745-s19/www/lectures/L8-Induction-Variables.pdf
Workaround
None
Workaround Description
No response
Additional Context
No response
Project Impact
None
Blocker Context
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: