-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[EarlyCSE] Rematerialize alignment assumption. #109131
Draft
fhahn
wants to merge
7
commits into
llvm:main
Choose a base branch
from
fhahn:earlycse-align-assumption
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−17
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2268c8c
[PhaseOrdering] Add eest making sure alignment doesn't get dropped.
fhahn a0f9839
[EarlyCSE] Rematerialize alignment assumption.
fhahn 29d08d5
!fixup check noundef
fhahn 8d9091b
Use computeKnownBits.
fhahn 4f21639
Remove align assumptions if possible.
fhahn 8441043
step
fhahn 1e2b44f
[InstCombine] Fold align assume into load's !align metadata if possible
fhahn 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 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 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 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 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
80 changes: 80 additions & 0 deletions
80
llvm/test/Transforms/PhaseOrdering/infer-align-from-assumption.ll
This file contains 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,80 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -passes='default<O3>' -S %s | FileCheck %s | ||
|
||
target triple = "arm64-apple-macosx" | ||
|
||
declare void @llvm.assume(i1 noundef) | ||
|
||
define i32 @entry(ptr %0) { | ||
; CHECK-LABEL: define i32 @entry( | ||
; CHECK-SAME: ptr nocapture [[TMP0:%.*]]) local_unnamed_addr { | ||
; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP0]], align 8, !align [[META0:![0-9]+]] | ||
; CHECK-NEXT: [[DOT0_COPYLOAD_I_I_I:%.*]] = load i32, ptr [[TMP2]], align 4 | ||
; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @swap(i32 [[DOT0_COPYLOAD_I_I_I]]) | ||
; CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i8, ptr [[TMP4]], i64 4 | ||
; CHECK-NEXT: store ptr [[TMP5]], ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: [[DOT0_COPYLOAD_I_I_I1:%.*]] = load i32, ptr [[TMP5]], align 4 | ||
; CHECK-NEXT: [[TMP6:%.*]] = tail call i32 @swap(i32 [[DOT0_COPYLOAD_I_I_I1]]) | ||
; CHECK-NEXT: [[TMP7:%.*]] = load ptr, ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i8, ptr [[TMP7]], i64 4 | ||
; CHECK-NEXT: store ptr [[TMP8]], ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: ret i32 [[TMP6]] | ||
; | ||
%2 = call i32 @fn1(ptr %0) | ||
%3 = call i32 @fn1(ptr %0) | ||
ret i32 %3 | ||
} | ||
|
||
|
||
define i32 @fn1(ptr %0) { | ||
; CHECK-LABEL: define i32 @fn1( | ||
; CHECK-SAME: ptr nocapture [[TMP0:%.*]]) local_unnamed_addr { | ||
; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP0]], align 8, !align [[META0]] | ||
; CHECK-NEXT: [[DOT0_COPYLOAD_I_I:%.*]] = load i32, ptr [[TMP2]], align 4 | ||
; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @swap(i32 [[DOT0_COPYLOAD_I_I]]) | ||
; CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i8, ptr [[TMP4]], i64 4 | ||
; CHECK-NEXT: store ptr [[TMP5]], ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: ret i32 [[TMP3]] | ||
; | ||
%2 = call i32 @fn2(ptr %0) | ||
ret i32 %2 | ||
} | ||
|
||
define i32 @fn2(ptr %0) { | ||
; CHECK-LABEL: define i32 @fn2( | ||
; CHECK-SAME: ptr nocapture [[TMP0:%.*]]) local_unnamed_addr { | ||
; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP0]], align 8, !align [[META0]] | ||
; CHECK-NEXT: [[DOT0_COPYLOAD_I:%.*]] = load i32, ptr [[TMP2]], align 4 | ||
; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @swap(i32 [[DOT0_COPYLOAD_I]]) | ||
; CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i8, ptr [[TMP4]], i64 4 | ||
; CHECK-NEXT: store ptr [[TMP5]], ptr [[TMP0]], align 8 | ||
; CHECK-NEXT: ret i32 [[TMP3]] | ||
; | ||
%2 = load ptr, ptr %0, align 8 | ||
%3 = call i32 @load_assume_aligned(ptr %2) | ||
%4 = load ptr, ptr %0, align 8 | ||
%5 = getelementptr i8, ptr %4, i64 4 | ||
store ptr %5, ptr %0, align 8 | ||
ret i32 %3 | ||
} | ||
|
||
define i32 @load_assume_aligned(ptr %0) { | ||
; CHECK-LABEL: define i32 @load_assume_aligned( | ||
; CHECK-SAME: ptr [[TMP0:%.*]]) local_unnamed_addr { | ||
; CHECK-NEXT: [[DOT0_COPYLOAD:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
; CHECK-NEXT: [[TMP2:%.*]] = tail call i32 @swap(i32 [[DOT0_COPYLOAD]]) | ||
; CHECK-NEXT: ret i32 [[TMP2]] | ||
; | ||
call void @llvm.assume(i1 true) [ "align"(ptr %0, i64 4) ] | ||
%.0.copyload = load i32, ptr %0, align 1 | ||
%2 = call i32 @swap(i32 %.0.copyload) | ||
ret i32 %2 | ||
} | ||
|
||
declare i32 @swap(i32) | ||
;. | ||
; CHECK: [[META0]] = !{i64 4} | ||
;. |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need
!noundef
for this transform.!align
by itself only returns poison, while the assumption converts it into IUB.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be updated, thanks!