<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - instcombine transforms arithmetic into xor which can't be analyzed by ScalarEvolution"
   href="https://bugs.llvm.org/show_bug.cgi?id=32706">32706</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>instcombine transforms arithmetic into xor which can't be analyzed by ScalarEvolution
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>efriedma@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>C Testcase:

unsigned a(unsigned x, unsigned y) { return 4*(-1-x+y); }

Resulting IR (clang -O2 -emit-llvm):

define i32 @a(i32 %x, i32 %y) local_unnamed_addr #0 {
entry:
  %sub = xor i32 %x, 1073741823
  %add = add i32 %sub, %y
  %mul = shl i32 %add, 2
  ret i32 %mul
}

Result of passing this IR to opt -analyze -scalar-evolution:

Printing analysis 'Scalar Evolution Analysis' for function 'a':
Classifying expressions for: @a
  %sub = xor i32 %x, 1073741823
  -->  %sub U: full-set S: full-set
  %add = add i32 %sub, %y
  -->  (%y + %sub) U: full-set S: full-set
  %mul = shl i32 %add, 2
  -->  (4 * (%y + %sub)) U: [0,-3) S: [-2147483648,2147483645)
Determining loop execution counts for: @a


SelectionDAG generally manages to figure out the xor is actually a "not", but
ScalarEvolution currently does not.  (This is reduced from a more complicated
testcase where it actually does matter that ScalarEvolution can't analyze it.)</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>