[LLVMbugs] [Bug 2002] New: Incorrect iteration count for loop with signed ICMP condition

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat Feb 9 13:13:27 PST 2008


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

           Summary: Incorrect iteration count for loop with signed ICMP
                    condition
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P2
         Component: Global Analyses
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: wmatyjewicz at fastmail.fm
                CC: nicholas at mxc.ca, llvmbugs at cs.uiuc.edu


For the following LLVM code:

define void @foo(i8 signext %n) {
entry:
        br label %header
header:
        %i = phi i8 [ -100, %entry ], [ %i.inc, %next ]
        %cond = icmp slt i8 %i, %n
        br i1 %cond, label %next, label %return
next:
        %i.inc = add i8 %i, 1
        br label %header
return:
        ret void
}

which more or less represents this high-level loop:

char n = ...;
for (char i = -100; i < n; ++i)
  ;

scalar evolution determines loop iteration count as: ( 0 smax ( 100 +  %n)).

In my opinion this is incorrect. Suppose, %n=100. Then 100 + %n becomes -56
(unsigned 200) and loop iteration count is evaluated to 0.

If someone confirm the bug, I'll try to fix it.


-- 
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