<div dir="ltr"><div>Dear All</div><div><br></div><span lang="en"><span title="">I have a question about the getInductionVariable API.</span><br><span title="">I was trying to get an induction variable (indvar) in the code below using the getInductionVariable API (LoopInfo class).</span></span><div></div><div><br></div><div><b>C file</b><br></div><div>void test(int val) {</div><div>  int sum = 0, i = 0;<br></div><div>  for (i = 0; i < val; i++) {</div><div>      sum += i;<br></div><div>  }<br></div><div>}</div><div><br></div><div><b>IR (with mem2reg pass)</b><br></div><div>; Function Attrs: nounwind<br>define dso_local void @test(i32 %0) #0 {<br>  br label %2<br>2:                                                ; preds = %6, %1<br>  %.01 = phi i32 [ 0, %1 ], [ %5, %6 ]<br>  %.0 = phi i32 [ 0, %1 ], [ %7, %6 ]<br>  %3 = icmp slt i32 %.0, %0<br>  br i1 %3, label %4, label %8 <- <span style="color:rgb(204,204,204)"><span style="background-color:rgb(0,0,255)"><b>Why don't check this BranchInst ?</b></span></span><br>4:                                                ; preds = %2<br>  %5 = add nsw i32 %.01, %.0<br>  br label %6<br>6:                                                ; preds = %4<br>  %7 = add nsw i32 %.0, 1<br> <b> br label %2  <- <span style="background-color:rgb(255,0,0)">checked it whether isCondition by getLatchCmpInst API(called by getInductionVariable API)</span></b><br>8:                                                ; preds = %2<br>  ret void<br>}</div><div><br></div><div></div>Then I got null (no indvar) because BranchInst's number of operands was less than 2.(red block).<br><br>A CmpInst(compare with induction variable) is contained in the header of the loop.<br>But the getInductionVariable API checks only in a latch block(contains a branch back to the header of the loop)<br>is there a missing case that contains CmpInst in the header?<br><br>And if I use the getCanonicalInductionVariable API, I can get the variable 'i'(%. 01) as an indvar.<br><br>I checked the code implementing getInductionVariable and getCanonicalInductionVariable.<br>It seems that indvar and canonical indvar differ only in the starting number (0 or none).<br>Why not use the same way to detect the indvar between getInductionVariable and getCanonicalInductionVariable.<br><br>BR<br>ZIN<br></div>