[llvm-bugs] [Bug 32787] New: failed to eliminate pair-of-compares

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 25 06:12:38 PDT 2017


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

            Bug ID: 32787
           Summary: failed to eliminate pair-of-compares
           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

int foo(int x, int y) {
  return x > (900 - y) || x > (450 - y);
}

Or as optimized IR:

define i32 @foo(i32 %x, i32 %y) {
  %sub = sub nsw i32 900, %y
  %cmp = icmp slt i32 %sub, %x
  %sub1 = sub nsw i32 450, %y
  %cmp2 = icmp slt i32 %sub1, %x
  %narrow = or i1 %cmp, %cmp2
  %z = zext i1 %narrow to i32
  ret i32 %z
}

We can eliminate the first compare:
http://rise4fun.com/Alive/aC3

We already do that (probably in InstSimplify) if the code is written as:

int foo(int x, int y) {
  return (x + y) > 900 || (x + y) > 450;
}

define i32 @foo(i32 %x, i32 %y) {
  %add = add nsw i32 %y, %x
  %cmp2 = icmp sgt i32 %add, 450
  %z = zext i1 %cmp2 to i32
  ret i32 %z
}

-- 
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/20170425/ad7ca9b8/attachment-0001.html>


More information about the llvm-bugs mailing list