[llvm] [SPIR-V] Don't replace spirv.Type with spv_track_constant (PR #134448)
Cassandra Beckley via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 4 14:43:32 PDT 2025
https://github.com/cassiebeckley created https://github.com/llvm/llvm-project/pull/134448
Fixes #134417
>From 75a29347295d39883c88b460ada43a662c86184c Mon Sep 17 00:00:00 2001
From: Cassandra Beckley <cbeckley at google.com>
Date: Fri, 4 Apr 2025 14:39:49 -0700
Subject: [PATCH] [SPIR-V] Don't replace spirv.Type with spv_track_constant
Fixes #134417
---
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 14 +++-----------
llvm/test/CodeGen/SPIRV/inline/type.undef.ll | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 11 deletions(-)
create mode 100644 llvm/test/CodeGen/SPIRV/inline/type.undef.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 0067d2400529a..064e9c7074750 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -2062,21 +2062,13 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
}
Type *OpTy = Op->getType();
Value *OpTyVal = Op;
- if (OpTy->isTargetExtTy())
- OpTyVal = getNormalizedPoisonValue(OpTy);
Type *OpElemTy = GR->findDeducedElementType(Op);
Value *NewOp = Op;
- if (OpTy->isTargetExtTy()) {
+ TargetExtType *TargetTy = dyn_cast<TargetExtType>(OpTy);
+ if (TargetTy && TargetTy->getName() != "spirv.Type") {
+ OpTyVal = getNormalizedPoisonValue(OpTy);
NewOp = buildIntrWithMD(Intrinsic::spv_track_constant,
{OpTy, OpTyVal->getType()}, Op, OpTyVal, {}, B);
- if (isPointerTy(OpTy)) {
- if (OpElemTy) {
- GR->buildAssignPtr(B, OpElemTy, NewOp);
- } else {
- insertTodoType(NewOp);
- GR->buildAssignPtr(B, OpTy, NewOp);
- }
- }
}
if (!IsConstComposite && isPointerTy(OpTy) && OpElemTy != nullptr &&
OpElemTy != IntegerType::getInt8Ty(I->getContext())) {
diff --git a/llvm/test/CodeGen/SPIRV/inline/type.undef.ll b/llvm/test/CodeGen/SPIRV/inline/type.undef.ll
new file mode 100644
index 0000000000000..1b8a8428fc74c
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/inline/type.undef.ll
@@ -0,0 +1,17 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - | spirv-as - -o - | spirv-val %}
+
+%literal_32 = type target("spirv.Literal", 32)
+%literal_true = type target("spirv.Literal", 1)
+
+; CHECK-DAG: OpUnknown(21, 4) [[int_t:%[0-9]+]] 32 1
+%int_t = type target("spirv.Type", %literal_32, %literal_true, 21, 4, 32)
+
+; CHECK-DAG: {{%[0-9]+}} = OpTypeFunction [[int_t]]
+define %int_t @foo() {
+entry:
+; CHECK-DAG: [[undef:%[0-9]+]] = OpUndef [[int_t]]
+; CHECK-DAG: OpReturnValue [[undef]]
+ ret %int_t undef
+}
More information about the llvm-commits
mailing list