[llvm] [IR] `select` should reject token-like types (PR #219162)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 02:58:12 PDT 2026


https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/219162

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

>From e77c18fa7cd48e7a577b95276ab1daf58ff8619d Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Thu, 27 Aug 2026 11:25:47 +0530
Subject: [PATCH] [IR] `select` should reject token-like types

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
---
 llvm/lib/IR/Verifier.cpp                               | 3 +++
 llvm/test/CodeGen/DirectX/ResourceAccess/non-unique.ll | 3 ++-
 llvm/test/Verifier/tokenlike2.ll                       | 9 +++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Verifier/tokenlike2.ll

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
+}



More information about the llvm-commits mailing list