-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Reassociate] Preserve NSW flags after expr tree rewriting #93105
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
Merged
AlexMaclean
merged 9 commits into
llvm:main
from
akshayrdeodhar:upstream/reassociate-nsw
May 28, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c8edf9b
[Reassociate] Preserve NSW flags after expr tree rewriting
akshayrdeodhar 685bfba
avoid computing isKnownNonNegative when possible, clang-format
akshayrdeodhar 99ae09c
Merge branch 'main' into upstream/reassociate-nsw
akshayrdeodhar 27adaf4
Add negative test, move note to header file
akshayrdeodhar 64d0b75
Cleanup OverflowTracking constructor
akshayrdeodhar 92bac25
Merge branch 'main' into upstream/reassociate-nsw
akshayrdeodhar b8e1d8d
formatting: drop braces
akshayrdeodhar 9982b8e
Merge branch 'main' into upstream/reassociate-nsw
akshayrdeodhar beedd72
formatting, correct comment
akshayrdeodhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: opt < %s -passes=reassociate -S | FileCheck %s | ||
define i32 @nsw_preserve_nonnegative(ptr %ptr0, ptr %ptr1, ptr %ptr2) { | ||
; CHECK-LABEL: define i32 @nsw_preserve_nonnegative( | ||
; CHECK-SAME: ptr [[PTR0:%.*]], ptr [[PTR1:%.*]], ptr [[PTR2:%.*]]) { | ||
; CHECK-NEXT: [[V0:%.*]] = load i32, ptr [[PTR0]], align 4, !range [[RNG0:![0-9]+]] | ||
; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[PTR1]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[PTR2]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[ADD0:%.*]] = add nsw i32 [[V1]], [[V0]] | ||
; CHECK-NEXT: [[ADD1:%.*]] = add nsw i32 [[ADD0]], [[V2]] | ||
; CHECK-NEXT: ret i32 [[ADD1]] | ||
; | ||
%v0 = load i32, ptr %ptr0, !range !1 | ||
%v1 = load i32, ptr %ptr1, !range !1 | ||
%v2 = load i32, ptr %ptr2, !range !1 | ||
%add0 = add nsw i32 %v1, %v2 | ||
%add1 = add nsw i32 %add0, %v0 | ||
ret i32 %add1 | ||
} | ||
|
||
define i32 @nsw_preserve_nuw_nsw(ptr %ptr0, ptr %ptr1, ptr %ptr2) { | ||
; CHECK-LABEL: define i32 @nsw_preserve_nuw_nsw( | ||
; CHECK-SAME: ptr [[PTR0:%.*]], ptr [[PTR1:%.*]], ptr [[PTR2:%.*]]) { | ||
; CHECK-NEXT: [[V0:%.*]] = load i32, ptr [[PTR0]], align 4 | ||
; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[PTR1]], align 4 | ||
; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[PTR2]], align 4 | ||
; CHECK-NEXT: [[ADD0:%.*]] = add nuw nsw i32 [[V1]], [[V0]] | ||
; CHECK-NEXT: [[ADD1:%.*]] = add nuw nsw i32 [[ADD0]], [[V2]] | ||
; CHECK-NEXT: ret i32 [[ADD1]] | ||
; | ||
%v0 = load i32, ptr %ptr0 | ||
%v1 = load i32, ptr %ptr1 | ||
%v2 = load i32, ptr %ptr2 | ||
%add0 = add nuw nsw i32 %v1, %v2 | ||
%add1 = add nuw nsw i32 %add0, %v0 | ||
ret i32 %add1 | ||
} | ||
|
||
define i32 @nsw_dont_preserve_negative(ptr %ptr0, ptr %ptr1, ptr %ptr2) { | ||
; CHECK-LABEL: define i32 @nsw_dont_preserve_negative( | ||
; CHECK-SAME: ptr [[PTR0:%.*]], ptr [[PTR1:%.*]], ptr [[PTR2:%.*]]) { | ||
; CHECK-NEXT: [[V0:%.*]] = load i32, ptr [[PTR0]], align 4 | ||
; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[PTR1]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[PTR2]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[ADD0:%.*]] = add i32 [[V1]], [[V0]] | ||
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[ADD0]], [[V2]] | ||
; CHECK-NEXT: ret i32 [[ADD1]] | ||
; | ||
%v0 = load i32, ptr %ptr0 | ||
%v1 = load i32, ptr %ptr1, !range !1 | ||
%v2 = load i32, ptr %ptr2, !range !1 | ||
%add0 = add nsw i32 %v1, %v2 | ||
%add1 = add nsw i32 %add0, %v0 | ||
ret i32 %add1 | ||
} | ||
|
||
define i32 @nsw_nopreserve_notallnsw(ptr %ptr0, ptr %ptr1, ptr %ptr2) { | ||
; CHECK-LABEL: define i32 @nsw_nopreserve_notallnsw( | ||
; CHECK-SAME: ptr [[PTR0:%.*]], ptr [[PTR1:%.*]], ptr [[PTR2:%.*]]) { | ||
; CHECK-NEXT: [[V0:%.*]] = load i32, ptr [[PTR0]], align 4, !range [[RNG0:![0-9]+]] | ||
; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[PTR1]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[V2:%.*]] = load i32, ptr [[PTR2]], align 4, !range [[RNG0]] | ||
; CHECK-NEXT: [[ADD0:%.*]] = add i32 [[V1]], [[V0]] | ||
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[ADD0]], [[V2]] | ||
; CHECK-NEXT: ret i32 [[ADD1]] | ||
; | ||
%v0 = load i32, ptr %ptr0, !range !1 | ||
%v1 = load i32, ptr %ptr1, !range !1 | ||
%v2 = load i32, ptr %ptr2, !range !1 | ||
%add0 = add nsw i32 %v1, %v2 | ||
%add1 = add i32 %add0, %v0 | ||
ret i32 %add1 | ||
} | ||
|
||
; Positive 32 bit integers | ||
!1 = !{i32 0, i32 2147483648} | ||
;. | ||
; CHECK: [[RNG0]] = !{i32 0, i32 -2147483648} | ||
;. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.