[llvm-bugs] [Bug 27431] New: cse or gvn should replace opposite icmp with xor by true

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 19 18:04:08 PDT 2016


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

            Bug ID: 27431
           Summary: cse or gvn should replace opposite icmp with xor by
                    true
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nlewycky at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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.

-- 
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/20160420/e1850039/attachment.html>


More information about the llvm-bugs mailing list