Consider the input file qappl.ll. Look into bb101 and next BBs. This code corresponds to the following code in cpp (this is extract from Qt): for (i=0; (UINT)mouseTbl[i] != msg.message || !mouseTbl[i]; i += 3) ; if (!mouseTbl[i]) return false; type = (QEvent::Type)mouseTbl[++i]; button = mouseTbl[++i]; qappl.out.ll is output from opt -indvars. We have: %tmp107 = seteq uint %tmp103, %tmp106 ; <bool> [#uses=1] br bool %tmp107, label %cond_next109, label %bb98 cond_next109: ; preds = %bb101 %exitcond = setne uint %indvar, 0 ; <bool> [#uses=1] br bool %exitcond, label %bb98, label %bb114 %tmp103 corresponds to mouseTbl[i], %tmp106 - to msg.message. %indvar corresponds to i/3. Let us assume, that they equals, when i!=0. We have: %tmp107 = true => branch to cond_next109 => %exitcond = true => branch to bb98 And we have infinite loop here :(
Created attachment 475 [details] Source file [qapp.ll]
Created attachment 476 [details] Opt output [qappl.out.ll]
Devang, can you take a look at this when you get a chance? Thx, -Chris
Devang, any news on this one?
Reduced testcase: static const char foo[] = "\0abc"; int test(int J) { int i; for (i = 0; i == 0 || foo[i] != 0; ++i) ; return i; } void main() { printf("%d\n", test(0)); } $ llvm-gcc t.c -S -o - -O0 -emit-llvm | llvm-as | opt -mem2reg -instcombine -indvars -adce | lli 0 $ gcc t.c $ ./a.out 4
Fixed. Testcase here: Transforms/IndVarsSimplify/2007-01-06-TripCount.ll Patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070101/042170.html -Chris