[LLVMbugs] [Bug 20189] New: Preserving nsw/nuw for x-(-A)=>x+A is unsafe

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 1 21:56:05 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20189

            Bug ID: 20189
           Summary: Preserving nsw/nuw for x-(-A)=>x+A is unsafe
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: ASSIGNED
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: wujingyue at gmail.com
          Reporter: wujingyue at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

When optimizing x-(-A) to x+A, the current logic of preserving nsw/nuw has a
hole.

For example, the current logic transforms "x -nsw (0-A)" to "x +nsw A".
However, when x = a = INT_MIN = -2^31, "x -nsw (0 - A)" is defined but "x +nsw
A"
returns a poison value. The following test case exposes the bug. 

define i32 @test37(i32 %A, i32 %x) {
  %B = sub i32 0, %A
  %C = sub nsw i32 %x, %B
  ret i32 %C
; CHECK-LABEL: @test37(
; CHECK: %C = add i32 %x, %A
; CHECK: ret i32 %C
}

To fix this issue, we need to consider the nsw/nuw of both minuses in x-(-A).
If both of them are marked nsw/nuw, we can preserve the nsw/nuw in the result
x+A.

-- 
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/20140702/e95e3ca1/attachment.html>


More information about the llvm-bugs mailing list