[LLVMbugs] [Bug 2607] New: SCEV miscomputes trip count for loop with SGT condition

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Jul 29 09:25:39 PDT 2008


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

           Summary: SCEV miscomputes trip count for loop with SGT condition
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu


Testcase:

#include <stdio.h>
int a(unsigned j) {unsigned i; for (i = 0; (int)i > (int)j; i--) {} return i;}
int main() {printf("%d", a(0x80000000));}

Compare the output with llvm-gcc with "-O0" vs. "-O3 -fno-inline" to see the
issue.

Relevant chunk from ScalarEvolutionsImpl::ComputeIterationCount:
  case ICmpInst::ICMP_SGT: {
    SCEVHandle TC = HowManyLessThans(SE.getNegativeSCEV(LHS),
                                     SE.getNegativeSCEV(RHS), L, true);
    if (!isa<SCEVCouldNotCompute>(TC)) return TC;
    break;
  }

The calls to getNegativeSCEV should be calls to getNotSCEV; negation doesn't
properly flip the comparison when one side is INT_MIN.  (It looked suspicious
when I saw it, although it took a little while to come up with a testcase.)

I'll throw together a patch later.


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