-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Don't unify divergent exit nodes with musttail
calls
#126395
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
shiltian
merged 1 commit into
main
from
users/shiltian/do-not-unify-divergent-exit-nodes-with-musttail
Feb 10, 2025
Merged
[AMDGPU] Don't unify divergent exit nodes with musttail
calls
#126395
shiltian
merged 1 commit into
main
from
users/shiltian/do-not-unify-divergent-exit-nodes-with-musttail
Feb 10, 2025
+57
−1
Conversation
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
@llvm/pr-subscribers-backend-amdgpu Author: Shilei Tian (shiltian) ChangesFixes SWDEV-512254. Full diff: https://github.com/llvm/llvm-project/pull/126395.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
index fda2a38c2464e00..d087fbc86545c99 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
@@ -215,7 +215,10 @@ bool AMDGPUUnifyDivergentExitNodesImpl::run(Function &F, DominatorTree *DT,
PDT.roots(), [&](auto BB) { return !isUniformlyReached(UA, *BB); });
for (BasicBlock *BB : PDT.roots()) {
- if (isa<ReturnInst>(BB->getTerminator())) {
+ if (auto *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
+ auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode());
+ if (CI && CI->isMustTailCall())
+ continue;
if (HasDivergentExitBlock)
ReturningBlocks.push_back(BB);
} else if (isa<UnreachableInst>(BB->getTerminator())) {
diff --git a/llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll b/llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll
new file mode 100644
index 000000000000000..2f367d64351089c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=amdgpu-unify-divergent-exit-nodes -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a %s -o - | FileCheck %s
+
+define void @spill_sgpr_with_tail_call() {
+; CHECK-LABEL: define void @spill_sgpr_with_tail_call(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[L1:%.*]] = load i1, ptr null, align 1
+; CHECK-NEXT: br i1 [[L1]], label %[[SW_C:.*]], label %[[SW_D:.*]]
+; CHECK: [[SW_D]]:
+; CHECK-NEXT: musttail call void null()
+; CHECK-NEXT: ret void
+; CHECK: [[SW_C]]:
+; CHECK-NEXT: ret void
+;
+ %L1 = load i1, ptr null, align 1
+ br i1 %L1, label %SW_C, label %SW_D
+
+SW_D:
+ musttail call void null()
+ ret void
+
+SW_C:
+ ret void
+}
+
|
musttail
calls
arsenm
reviewed
Feb 9, 2025
llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AMDGPU/do-not-unify-divergent-exit-nodes-with-musttail.ll
Outdated
Show resolved
Hide resolved
Fixes SWDEV-512254.
2a5fbdf
to
aa55874
Compare
arsenm
approved these changes
Feb 10, 2025
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.
We have an issue if we have a musttail indirect call with a divergent call target
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
searlmc1
pushed a commit
to ROCm/llvm-project
that referenced
this pull request
Jun 19, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes SWDEV-512254.