-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CodeGenPrepare] Filter out unrecreatable addresses from memory optimization #143566
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7f4b17
[CodeGenPrepare] Handle address sinking obtained from invoke
e-kud 8d928bc
Don't try to sink addresses that we can't recreate
e-kud 0c804d3
Rename the test
e-kud a5b5b9a
Add tests for args and globals
e-kud 81ddd17
Skip anything that is not an instruction from current basic block
e-kud 360e261
Merge branch 'main' into cg-prepare-term-addr
e-kud ccf28b5
Skip only instructions from different basic blocks
e-kud 85eb67b
Merge branch 'main' into cg-prepare-term-addr
e-kud 5215657
Merge branch 'main' into cg-prepare-term-addr
e-kud 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
106 changes: 106 additions & 0 deletions
106
llvm/test/Transforms/CodeGenPrepare/X86/sink-addr-recreate.ll
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,106 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -S -p 'require<profile-summary>,codegenprepare' -cgpp-huge-func=0 < %s | FileCheck %s | ||
|
|
||
| target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | ||
| target triple = "x86_64-grtev4-linux-gnu" | ||
|
|
||
| @globalptr = external global ptr | ||
| declare ptr @get_ptr(i64) | ||
|
|
||
| ; Can't recreate invoke instruction | ||
|
|
||
| define void @addr_from_invoke() personality ptr null { | ||
| ; CHECK-LABEL: define void @addr_from_invoke() personality ptr null { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: [[PTR:%.*]] = invoke ptr @get_ptr(i64 0) | ||
| ; CHECK-NEXT: to label %[[BODY_1:.*]] unwind label %[[EHCLEANUP:.*]] | ||
| ; CHECK: [[EHCLEANUP]]: | ||
| ; CHECK-NEXT: [[PAD:%.*]] = cleanuppad within none [] | ||
| ; CHECK-NEXT: cleanupret from [[PAD]] unwind to caller | ||
| ; CHECK: [[BODY_1]]: | ||
| ; CHECK-NEXT: [[GEP1:%.*]] = bitcast ptr [[PTR]] to ptr | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[GEP1]], align 4 | ||
| ; CHECK-NEXT: [[TMP0:%.*]] = bitcast ptr [[PTR]] to ptr | ||
| ; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr [[TMP0]], align 4 | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP0]], align 4 | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %ptr = invoke ptr @get_ptr(i64 0) to label %body.1 unwind label %ehcleanup | ||
|
|
||
| body.2: | ||
| %unused = load <4 x i32>, ptr %gep, align 4 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| ret void | ||
|
|
||
| ehcleanup: | ||
| %pad = cleanuppad within none [] | ||
| cleanupret from %pad unwind to caller | ||
|
|
||
| body.1: | ||
| %gep = getelementptr { i32 }, ptr %ptr, i64 0, i32 0 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| br label %body.2 | ||
| } | ||
|
|
||
| define void @addr_from_arg(ptr %ptr, i1 %p) { | ||
| ; CHECK-LABEL: define void @addr_from_arg( | ||
| ; CHECK-SAME: ptr [[PTR:%.*]], i1 [[P:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: br i1 [[P]], label %[[BODY_1:.*]], label %[[EXIT:.*]] | ||
| ; CHECK: [[EXIT]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; CHECK: [[BODY_1]]: | ||
| ; CHECK-NEXT: [[TMP0:%.*]] = bitcast ptr [[PTR]] to ptr | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP0]], align 4 | ||
| ; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr [[PTR]], align 4 | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[PTR]], align 4 | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| br i1 %p, label %body.1, label %exit | ||
|
|
||
| body.2: | ||
| %unused = load <4 x i32>, ptr %gep, align 4 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| ret void | ||
|
|
||
| exit: | ||
| ret void | ||
|
|
||
| body.1: | ||
| %gep = getelementptr { i32 }, ptr %ptr, i64 0, i32 0 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| br label %body.2 | ||
| } | ||
|
|
||
| define void @addr_from_global(i1 %p) { | ||
| ; CHECK-LABEL: define void @addr_from_global( | ||
| ; CHECK-SAME: i1 [[P:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: br i1 [[P]], label %[[BODY_1:.*]], label %[[EXIT:.*]] | ||
| ; CHECK: [[EXIT]]: | ||
| ; CHECK-NEXT: ret void | ||
| ; CHECK: [[BODY_1]]: | ||
| ; CHECK-NEXT: [[GEP1:%.*]] = bitcast ptr @globalptr to ptr | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[GEP1]], align 4 | ||
| ; CHECK-NEXT: [[UNUSED:%.*]] = load <4 x i32>, ptr @globalptr, align 4 | ||
| ; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr @globalptr, align 4 | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| br i1 %p, label %body.1, label %exit | ||
|
|
||
| body.2: | ||
| %unused = load <4 x i32>, ptr %gep, align 4 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| ret void | ||
|
|
||
| exit: | ||
| ret void | ||
|
|
||
| body.1: | ||
| %gep = getelementptr { i32 }, ptr @globalptr, i64 0, i32 0 | ||
| store <4 x i32> zeroinitializer, ptr %gep, align 4 | ||
| br label %body.2 | ||
| } |
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.
Here we can change the predicate to
To skip arguments and global pointers. I'm not sure if it is completely correct.
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.
I prefer this condition. We should not modify a memory access instruction with pointer comes from argument or global value directly.
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.
Done. I also added tests for arguments and globals. @weiguozhi you may be interested that we don't reuse addresses in these cases: https://godbolt.org/z/q8fzce4ov