<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 --- - cse or gvn should replace opposite icmp with xor by true"
   href="https://llvm.org/bugs/show_bug.cgi?id=27431">27431</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>cse or gvn should replace opposite icmp with xor by true
          </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>normal
          </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>nlewycky@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>Reduced testcase:

; ModuleID = 'gvn-icmp.ll'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare void @use(i1)

define void @fn1(i32 %A) {
entry:
  %iszero = icmp eq i32 %A, 0
  %isnotzero = icmp ne i32 %A, 0  ;; %isnotzero = xor i1 %iszero, true
  tail call void @use(i1 %iszero)
  tail call void @use(i1 %isnotzero)
  ret void
}

Something in llvm should turn subsequent comparisons into nots of the original
comparison to expose further correlations between values. In particular they
should work across blocks, the right places for this might be early-cse and
gvn.

Here's a larger C testcase, 77.c from Regehr's souper results:

  int a;
  char b;
  int fn1() { return a && b || a && b; }

If I apply the proposed transformation by hand, it reduces from 12 instructions
in 3 blocks down to a single block with load+load+icmp+icmp+and+zext+ret.</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>