<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 --- - Another cse pass may be needed after LSR to clean up redundency introduced by SCEV expansion"
   href="https://llvm.org/bugs/show_bug.cgi?id=24442">24442</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Another cse pass may be needed after LSR to clean up redundency introduced by SCEV expansion
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>wmi@google.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>For the testcase 1.c below:

int a[1000];

int foo(int x, int y) {
  int i, total = 0;
  int m = (x < y) ? x : y;   // smin(x, y)
  for (i = 0; i < m; i++) {
    total += a[i];
  }
  return total;
}

~/workarea/llvm-r243653/build/bin/clang -O2 -S 1.c -o bad.s

In bad.s, we see that the smin is computed 5 times.

Loop iteration number is computed in SCEV form and expanded several times
separately by loop vectorization, loop unrolling and loop strength reduction
passes. The expansions introduces repeated computation, which however cannot be
removed because no late cse pass exists to cleanup those redundencies.

I try to add an instcombine pass and an early-cse pass after LSR, then smin is
computed 2 time in the generated good.s. It should be reduced to 1 but not,
because of another bug: <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - missing cse for smin/smax"
   href="show_bug.cgi?id=24441">https://llvm.org/bugs/show_bug.cgi?id=24441</a></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>