[llvm-bugs] [Bug 27409] New: ScalarEvolution::getConstantEvolutionLoopExitValue doesn't evualate loops corectly.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 18 13:21:44 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27409

            Bug ID: 27409
           Summary: ScalarEvolution::getConstantEvolutionLoopExitValue
                    doesn't evualate loops corectly.
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: williams at coherentlogix.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16230
  --> https://llvm.org/bugs/attachment.cgi?id=16230&action=edit
Test Case but write up and output files.

When we run the following test case.

#include <stdio.h>

int main() {
  int Test[10] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

  int i; 
  int Sum = 0; 
  for(i = 0 ; i < 1 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 0 ; i < 2 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 0 ; i < 3 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 3 ; i < 7 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 7 ; i < 10 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 8 ; i < 10 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 9 ; i < 10 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  Sum = 0; 
  for(i = 0 ; i < 10 ; i++) {
    Sum += Test[i] ; 
  } 
  printf("Sum = %d\n", Sum);

  return 0; 
}

We expect the following output:

Sum = 10
Sum = 19
Sum = 27
Sum = 22
Sum = 6
Sum = 3
Sum = 1
Sum = 55

However when we ran this program with clang using -O3 we got the following
output:

Sum = 10
Sum = 10
Sum = 19
Sum = 18
Sum = 6
Sum = 3
Sum = 1
Sum = 55

We have tracked the problem down to the following function:

onstant *
ScalarEvolution::getConstantEvolutionLoopExitValue(PHINode *PN,
                                                   const APInt &BEs,
                                                   const Loop *L)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160418/3f8db165/attachment.html>


More information about the llvm-bugs mailing list