Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving nsw/nuw for x-(-A)=>x+A is unsafe #20563

Closed
llvmbot opened this issue Jul 2, 2014 · 2 comments
Closed

Preserving nsw/nuw for x-(-A)=>x+A is unsafe #20563

llvmbot opened this issue Jul 2, 2014 · 2 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 2, 2014

Bugzilla Link 20189
Resolution FIXED
Resolved on Jul 30, 2014 23:50
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @majnemer,@nunoplopes,@regehr

Extended Description

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.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 2, 2014

assigned to @majnemer

@majnemer
Copy link
Mannequin

majnemer mannequin commented Jul 31, 2014

Fixed with r214384 and r214385.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

1 participant