[LLVMbugs] [Bug 1533] NEW: -indvars pass fails to rewirte the exit condition

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Jul 2 11:44:00 PDT 2007


http://llvm.org/bugs/show_bug.cgi?id=1533

           Summary: -indvars pass fails to rewirte the exit condition
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Loop Optimizer
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: zhiruz at gmail.com


//// C code ////
#define N 128 // try 32 instead
int array[N];

void loop(int x)
{
    int i;
    for (i = N - 1; i >= 0; --i)
        array[i] = x;
}
//////////////

"llvm-gcc -c -emit-llvm -O3 loop.c -o loop.bc" followed by "opt -indvars 
loop.bc -o new.bc -f" will yield this:

define void @loop(i32 %x) {
entry:
        br label %bb

bb:             ; preds = %bb, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next2, %bb ]         ; <i32> 
[#uses=3]
        %i.010.0 = sub i32 127, %indvar         ; <i32> [#uses=1]
        %tmp1 = getelementptr [128 x i32]* @array, i32 0, i32 %i.010.0
          ; <i32*> [#uses=1]
        store i32 %x, i32* %tmp1
        %tmp4 = sub i32 126, %indvar            ; <i32> [#uses=1]
        %tmp7 = icmp sgt i32 %tmp4, -1          ; <i1> [#uses=1]
        %indvar.next2 = add i32 %indvar, 1              ; <i32> [#uses=1]
        br i1 %tmp7, label %bb, label %return

return:         ; preds = %bb
        ret void
}


Interestingly, if I define N to be 32 instead (actually any integer number < 
102 is good), everything will be just fine.

See below:

define void @loop(i32 %x) {
entry:
        br label %bb

bb:             ; preds = %bb, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next2, %bb ]         ; <i32> 
[#uses=2]
        %i.010.0 = sub i32 31, %indvar          ; <i32> [#uses=1]
        %tmp1 = getelementptr [32 x i32]* @array, i32 0, i32 %i.010.0
           ; <i32*> [#uses=1]
        store i32 %x, i32* %tmp1
        %indvar.next2 = add i32 %indvar, 1              ; <i32> [#uses=2]
        %exitcond3 = icmp eq i32 %indvar.next2, 32              ; <i1> [#uses=1]
        br i1 %exitcond3, label %return, label %bb

return:         ; preds = %bb
        ret void
}



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list