I am trying to obtain the canonical induction variable for a loop in a loop pass, given its reference L*, using L->getCanonicalInductionVariable().
But many of the loops I encounter are not in canonical form. For ex:
for (int i = 10; i < 20 ; i++) {
....
}
According to llvm documentation http://llvm.org/docs/Passes.html#indvars-canonicalize-induction-variables) , using the "indvars" pass in "opt" should do the trick by converting the loops induction variable into canonical form. I have tried running:
opt -mem2reg -indvars < test.bc > optTest.bc
where "test.bc" is a bit code format of the for-loop above. But the indvars pass seems to have no effect ( I have omitted the assembly code here, but I have checked it).
Later, using L->getCanonicalInductionVariable() returns null. I have also tried using "indvars" with other passes like "loops", "loop-simplify" but to no avail.
Any idea on how to get this to work?