<div dir="ltr"><div><div>Hi Fellows,<br><br>
The goal is to find the
induction variable for a loop, where the induction variable increments
with the multiplication, division or shift operations, like this one:<br>
<br>
sz = 8;<br>
do {<br> <br> ... ... <br><br>
sz = sz / 2;<br>
} while (sz)<br>
<br>
Is SCEV capable of detecting the induction variable 'sz' in this case? The code snippet I am using to solve the problem is <br>
<br>
for each basic-block in a loop<br>
for each instruction J in a basic block<br>
if ( J is a PHINode) {<br>
const SCEV *S = SE->getSCEV(J);<br>
const SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(S);<br>
<br>
if (SARE) {<br>
const Loop *CurLoop = SARE->getLoop();<br>
<br>
if (CurLoop == L) {<br>
/* => J is the induction variable*/<br>
}<br>
} <br>
}<br>
<br>
SCEVAddRecExpr is said to be able to handle any polynomial
recurrence on the trip count of the loop. However, for my sample
program, The dyn_cast result SARE is always NULL ... hence getting me to think that SCEV is not capable of handling cases like i=i/2, which contradicts what was said in the LLVM API documentation. Thanks.<br><br></div>Best,<br>
</div>Paul<br></div>