[llvm-bugs] [Bug 36240] New: [InstCombine] icmp with sdiv operand transformed strangely

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 5 11:20:59 PST 2018


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

            Bug ID: 36240
           Summary: [InstCombine] icmp with sdiv operand transformed
                    strangely
           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

define i1 @cmpdiv(i32 %x) {
  %d = sdiv i32 1, %x
  %c = icmp slt i32 %d, 0
  ret i1 %c
}

$ opt -instcombine cmpsignbit.ll -S
define i1 @cmpdiv(i32 %x) {
  %1 = add i32 %x, 1
  %2 = icmp ult i32 %1, 3
  %c1 = icmp slt i32 %x, 0
  %c = and i1 %2, %c1
  ret i1 %c

That's a weird way to write:
  %c = icmp eq i32 %x, -1

-------------------------------------------------------------------------------

Note that we don't do anything with this case:

define i1 @cmpdiv400(i32 %x) {
  %d = sdiv i32 400, %x
  %c = icmp slt i32 %d, 0
  ret i1 %c
}

But we could turn this into a range check:

Name: sdiv400
  %d = sdiv i32 400, %x
  %c = icmp slt i32 %d, 0
=>
 %c1 = icmp sge i32 %x, -400  
 %c2 = icmp slt i32 %x, 0
 %c = and i1 %c1, %c2 

https://rise4fun.com/Alive/cDM

...so whatever is trying to improve the 1st case could probably use
generalizing and fixing.

-- 
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/20180205/5f3b0be6/attachment.html>


More information about the llvm-bugs mailing list