[LLVMbugs] [Bug 10293] New: Load not hoisted out of loop with multiple exits

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 7 04:46:40 PDT 2011


           Summary: Load not hoisted out of loop with multiple exits
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: benny.kra at gmail.com
                CC: llvmbugs at cs.uiuc.edu

We compile this C code:

bool foo(const char *CurPtr) {
  for (unsigned i = 1; i != 7; ++i)
    if (CurPtr[i] != CurPtr[0])
      return false;
  return true;


define zeroext i1 @foo(i8* nocapture %CurPtr) nounwind readonly ssp {
  br label %for.cond

for.cond:                                         ; preds = %for.inc, %entry
  %indvar = phi i32 [ %phitmp, %for.inc ], [ 1, %entry ]
  %cmp = icmp eq i32 %indvar, 7
  br i1 %cmp, label %return, label %for.body

for.body:                                         ; preds = %for.cond
  %arrayidx = getelementptr i8* %CurPtr, i32 %indvar
  %tmp3 = load i8* %arrayidx, align 1, !tbaa !0
  %tmp6 = load i8* %CurPtr, align 1, !tbaa !0
  %cmp8 = icmp eq i8 %tmp3, %tmp6
  br i1 %cmp8, label %for.inc, label %return

for.inc:                                          ; preds = %for.body
  %phitmp = add i32 %indvar, 1
  br label %for.cond

return:                                           ; preds = %for.cond,
  %retval.0 = phi i1 [ false, %for.body ], [ true, %for.cond ]
  ret i1 %retval.0

The load of CurPtr[0] should be moved out of the loop. Recent versions of GCC
seem to be able to do this.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list