[llvm] [SPIRV] convergence anchor intrinsic does not have a parent token (PR #122230)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 10 00:06:03 PST 2025
https://github.com/ssahasra updated https://github.com/llvm/llvm-project/pull/122230
>From f474d32bd07bc03abd2142ca022fc4d2d167671d Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Thu, 9 Jan 2025 13:26:53 +0530
Subject: [PATCH 1/2] [SPIRV] convergence anchor intrinsic does not have a
parent token
---
.../Analysis/SPIRVConvergenceRegionAnalysis.cpp | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
index cc6daf7ef34426..9ac0f8700a3f66 100644
--- a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
@@ -56,20 +56,8 @@ getConvergenceTokenInternal(BasicBlockType *BB) {
"Output type must be an intrinsic instruction.");
for (auto &I : *BB) {
- if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
- switch (II->getIntrinsicID()) {
- case Intrinsic::experimental_convergence_entry:
- case Intrinsic::experimental_convergence_loop:
- return II;
- case Intrinsic::experimental_convergence_anchor: {
- auto Bundle = II->getOperandBundle(LLVMContext::OB_convergencectrl);
- assert(Bundle->Inputs.size() == 1 &&
- Bundle->Inputs[0]->getType()->isTokenTy());
- auto TII = dyn_cast<IntrinsicInst>(Bundle->Inputs[0].get());
- assert(TII != nullptr);
- return TII;
- }
- }
+ if (auto *CI = dyn_cast<ConvergenceControlInst>(&I)) {
+ return CI;
}
if (auto *CI = dyn_cast<CallInst>(&I)) {
>From 74bd77bcf46b01d394137fc2882e09a1a1dcbd17 Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Fri, 10 Jan 2025 13:34:48 +0530
Subject: [PATCH 2/2] add asserts to catch tokens incorrectly placed on entry
or anchor
---
llvm/include/llvm/IR/IntrinsicInst.h | 6 +++---
.../SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp | 4 ++++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index 3436216d478e38..6ccbb6b185c7d9 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -1873,13 +1873,13 @@ class ConvergenceControlInst : public IntrinsicInst {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
- bool isAnchor() {
+ bool isAnchor() const {
return getIntrinsicID() == Intrinsic::experimental_convergence_anchor;
}
- bool isEntry() {
+ bool isEntry() const {
return getIntrinsicID() == Intrinsic::experimental_convergence_entry;
}
- bool isLoop() {
+ bool isLoop() const {
return getIntrinsicID() == Intrinsic::experimental_convergence_loop;
}
};
diff --git a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
index 9ac0f8700a3f66..c23a6c3e8bbe85 100644
--- a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
@@ -57,6 +57,10 @@ getConvergenceTokenInternal(BasicBlockType *BB) {
for (auto &I : *BB) {
if (auto *CI = dyn_cast<ConvergenceControlInst>(&I)) {
+ // Make sure that the anchor or entry intrinsics did not reach here with a
+ // parent token. This should have failed the verifier.
+ assert(CI->isLoop() ||
+ !CI->getOperandBundle(LLVMContext::OB_convergencectrl));
return CI;
}
More information about the llvm-commits
mailing list