[LLVMdev] L->isLoopInvariant giving wrong results?
Sreeraj a
writetosrj at gmail.com
Wed Nov 17 02:20:59 PST 2010
Hi,
I'm trying to write a simple pass to print out Loop invariant instructions,
using the
Loop::isLoopInvariant(Instruction *I)
function. it is giving me false value on instructions which should be loop
invariant.
the code i am using is:
bool MyLoopPass::runOnLoop(Loop * L, LPPassManager &lpm){
BasicBlock* lat=L->getLoopLatch();
for (BasicBlock::iterator i = lat->begin(), e = lat->end(); i != e; ++i){
Instruction* hijk= i;
if(L->isLoopInvariant(hijk))
errs() << "hurray " << *hijk << " is loop invariant\n";
else
errs() << "bad luck\n";
}
return false;
}
the loop latch prints as:
bb: ; preds = %bb1
store i32 21, i32* %ij, align 4
store i32 10, i32* %j, align 4
%0 = load i32* %i, align 4
%1 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([4 x
i8]* @.str, i32 0, i32 0), i32 %0) nounwind
%2 = load i32* %i, align 4
%3 = sub nsw i32 %2, 1
store i32 %3, i32* %i, align 4
br label %bb1
the first instruction " store i32 21, i32* %ij, align 4"
is clearly loop invariant (corresponds to j=10; in c-code)
but all i am getting is "bad luck".
am i doing something wrong here? or is the function incomplete/wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101117/f0430294/attachment.html>
More information about the llvm-dev
mailing list