-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[AMDGPU] LRO: allow same-BB non-lookthrough users for PHI #160909
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
2 commits
Select commit
Hold shift + click to select a range
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
46 changes: 46 additions & 0 deletions
46
llvm/test/CodeGen/AMDGPU/lro-phi-samebb-nonlookthrough-store.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,46 @@ | ||
| ; RUN: opt -S -passes=amdgpu-late-codegenprepare \ | ||
| ; RUN: -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a %s | FileCheck %s | ||
|
|
||
| ; Goal: With a loop-header PHI in illegal vector type and a same-BB | ||
| ; non-lookthrough user (vector add) in the header, LRO should still coerce | ||
| ; the PHI to i32 because a profitable sink (store) exists across BB. | ||
|
|
||
| define amdgpu_kernel void @phi_samebb_nonlookthrough_store( | ||
| ptr addrspace(1) %out, <4 x i8> %v, i1 %exit) { | ||
| ; CHECK-LABEL: @phi_samebb_nonlookthrough_store( | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: ; preds = %entry, %loop | ||
| ; Loop-carried PHI in illegal vector type. | ||
| %acc = phi <4 x i8> [ zeroinitializer, %entry ], [ %acc.next, %loop ] | ||
|
|
||
| ; Same-BB non-lookthrough use in header. | ||
| %acc.next = add <4 x i8> %acc, %v | ||
|
|
||
| ; Make it a real loop: either iterate or exit to the sink block. | ||
| br i1 %exit, label %store, label %loop | ||
|
|
||
| store: ; preds = %loop | ||
| ; The across-BB sink: storing the PHI coerced to i32. | ||
| %acc.bc = bitcast <4 x i8> %acc to i32 | ||
| store i32 %acc.bc, ptr addrspace(1) %out, align 4 | ||
| ret void | ||
| } | ||
|
|
||
| ; After AMDGPULateCodeGenPrepare we expect: | ||
| ; - PHI is coerced to i32 | ||
| ; - A header bitcast materializes for the add | ||
| ; This proves the same-BB non-lookthrough user (add) did not get pruned | ||
| ; when the def is a PHI. | ||
|
|
||
| ; CHECK: loop: | ||
| ; CHECK: %[[ACC_TC:[^ ]+]] = phi i32 | ||
| ; CHECK: %[[ACC_TC_BC:[^ ]+]] = bitcast i32 %[[ACC_TC]] to <4 x i8> | ||
| ; CHECK: %[[ACC_NEXT:[^ ]+]] = add <4 x i8> %[[ACC_TC_BC]], %v | ||
| ; CHECK: br i1 %exit, label %store, label %loop | ||
| ; CHECK: store: | ||
| ; CHECK: %[[ACC_TC_BC2:[^ ]+]] = bitcast i32 %[[ACC_TC]] to <4 x i8> | ||
| ; CHECK: %[[ST_I32:[^ ]+]] = bitcast <4 x i8> %[[ACC_TC_BC2]] to i32 | ||
| ; CHECK: store i32 %[[ST_I32]], | ||
|
|
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.
should have test
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.
Added a minimal IR test (lro-phi-samebb-nonlookthrough-store.ll) that checks the same-BB filter looks at the user and allows non-lookthrough when the def is a PHI