[llvm-bugs] [Bug 41443] New: Canonicalize (-X srem Y) to -(X srem Y)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 9 09:22:05 PDT 2019


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

            Bug ID: 41443
           Summary: Canonicalize (-X srem Y) to -(X srem Y)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: chenzheng1030 at hotmail.com
                CC: llvm-bugs at lists.llvm.org

This is from code review comment of https://reviews.llvm.org/D60395
In that patch, canonicalization is done for '-X s/ Y', so it can save one div
for -(X/Y) and (-X/Y).

There should be same opportunity for srem.

----------------------------------------
Optimization: -X srem Y -> -(X srem Y)
Precondition: true
  %o0 = sub nsw i8 0, %x
  %r = srem i8 %o0, %y
=>
  %n0 = srem i8 %x, %y
  %r = sub nsw i8 0, %n0
Done: 1                                                                         
Optimization is correct


(X srem -Y) is not equal to -(X srem Y).

----------------------------------------
Optimization: X srem -Y -> -(X srem Y)
Precondition: true
  %t0 = sub nsw i8 0, %y
  %r  = sdiv i8 %x, %t0
=>
  %n0 = sdiv i8 %x, %y
  %r  = sub i8 0, %n0

ERROR: Target introduces undefined behavior for i8 %r                           

Example:
i8 %x  = poison
i8 %y  = 0xff (255, -1)
i8 %t0 = 0x01 (1)
source: poison
target: undefined

-- 
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/20190409/14eefa9f/attachment-0001.html>


More information about the llvm-bugs mailing list