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: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]
                CC: [email protected]


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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to