[llvm-bugs] [Bug 32401] New: [InstCombine] failed to canonicalize bitwise logic to icmps

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 23 15:31:16 PDT 2017


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

            Bug ID: 32401
           Summary: [InstCombine] failed to canonicalize bitwise logic to
                    icmps
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org

In D31290 (https://reviews.llvm.org/D31290), I had a hard time getting llvm to
produce the optimal scalar code that Eli suggested. 

The type is 'char' here, but that doesn't matter for the purpose of this bug.

char cmpeq_bitwise(char x0, char y0, char x1, char y1) {
  return ((x0 ^ y0) | (x1 ^ y1)) == 0;
}

char cmpeq_logical(char x0, char y0, char x1, char y1) {
  return ((x0 ^ y0) || (x1 ^ y1)) == 0;
}

Before we get to the codegen, we have a missing IR canonicalization of these
equivalent functions:

define i8 @cmpeq_bitwise(i8 %a, i8 %b, i8 %c, i8 %d) {
  %xor1 = xor i8 %a, %b
  %xor2 = xor i8 %c, %d
  %or = or i8 %xor1, %xor2
  %cmp = icmp eq i8 %or, 0
  %z = zext i1 %cmp to i8
  ret i8 %z
}

define i8 @cmpeq_logical(i8 %a, i8 %b, i8 %c, i8 %d) {
  %cmp1 = icmp eq i8 %a, %b
  %cmp2 = icmp eq i8 %c, %d
  %and = and i1 %cmp1, %cmp2
  %z = zext i1 %and to i8
  ret i8 %z
}

http://rise4fun.com/Alive/C6n

We should prefer the 2nd form because it has less instructions? FWIW, x86
codegen looks better for the 1st form, so we may need to reverse the transform
in the backend.

-- 
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/20170323/cb5b3dd6/attachment-0001.html>


More information about the llvm-bugs mailing list