[LLVMdev] SCEV and induction variable identification
Paul Vario
paul.paul.mit at gmail.com
Tue Apr 22 10:49:37 PDT 2014
Hi Fellows,
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:
sz = 8;
do {
... ...
sz = sz / 2;
} while (sz)
Is SCEV capable of detecting the induction variable 'sz' in this case?
The code snippet I am using to solve the problem is
for each basic-block in a loop
for each instruction J in a basic block
if ( J is a PHINode) {
const SCEV *S = SE->getSCEV(J);
const SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(S);
if (SARE) {
const Loop *CurLoop = SARE->getLoop();
if (CurLoop == L) {
/* => J is the induction variable*/
}
}
}
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.
Best,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140422/98ba8a81/attachment.html>
More information about the llvm-dev
mailing list