[llvm] [IR] `select` should reject token-like types (PR #219162)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 02:58:44 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
Author: Sameer Sahasrabuddhe (ssahasra)
<details>
<summary>Changes</summary>
Target extension types with the IsTokenLike property are meant to behave like tokens. The change in #<!-- -->154620 already rejected such types in phi nodes, function arguments, function return types and call parameters. Added this missing check in SelectInst::areInvalidOperands().
Some DirectX lit tests deliberately use token-like types in Phi or Select instructions, while disabling the verifier. This change disables the verifier in one more test to keep it working.
Assisted-By: GPT 5.6 Sol
---
Full diff: https://github.com/llvm/llvm-project/pull/219162.diff
3 Files Affected:
- (modified) llvm/lib/IR/Verifier.cpp (+3)
- (modified) llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll (+2-1)
- (added) llvm/test/Verifier/tokenlike2.ll (+9)
``````````diff
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f47cbccf171f4..83dce6a7142c0 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3571,6 +3571,9 @@ void Verifier::visitSelectInst(SelectInst &SI) {
SI.getOperand(2)),
"Invalid operands for select instruction!", &SI);
+ Check(!SI.getType()->isTokenLikeTy(),
+ "Select values cannot have token type!", &SI);
+
Check(SI.getTrueValue()->getType() == SI.getType(),
"Select values must have same type as select instruction!", &SI);
visitInstruction(SI);
diff --git a/llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll b/llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll
index 9f62197e805cd..03b475943ef24 100644
--- a/llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll
+++ b/llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll
@@ -1,4 +1,5 @@
-; RUN: not opt -S -dxil-resource-access -mtriple=dxil--shadermodel6.3-library %s 2>&1 | FileCheck %s
+; RUN: not opt -S -dxil-resource-access -disable-verify \
+; RUN: -mtriple=dxil--shadermodel6.3-library %s 2>&1 | FileCheck %s
; Test that a error message is generated for illegal resource accesses that do
; not access a unique global resource.
diff --git a/llvm/test/Verifier/tokenlike2.ll b/llvm/test/Verifier/tokenlike2.ll
new file mode 100644
index 0000000000000..64628550be019
--- /dev/null
+++ b/llvm/test/Verifier/tokenlike2.ll
@@ -0,0 +1,9 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+define void @f(i1 %cond, target("dx.RawBuffer", half, 1, 0) %A,
+ target("dx.RawBuffer", half, 1, 0) %B) {
+ %sel = select i1 %cond, target("dx.RawBuffer", half, 1, 0) %A,
+ target("dx.RawBuffer", half, 1, 0) %B
+; CHECK: Select values cannot have token type!
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/219162
More information about the llvm-commits
mailing list