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: unassignedb...@nondot.org
          Reporter: chenzheng1...@hotmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to