<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - ScalarEvolution::getConstantEvolutionLoopExitValue doesn't evualate loops corectly."
   href="https://llvm.org/bugs/show_bug.cgi?id=27409">27409</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ScalarEvolution::getConstantEvolutionLoopExitValue doesn't evualate loops corectly.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>williams@coherentlogix.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16230" name="attach_16230" title="Test Case but write up and output files.">attachment 16230</a> <a href="attachment.cgi?id=16230&action=edit" title="Test Case but write up and output files.">[details]</a></span>
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)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>