[llvm] [SPIR-V] Emit builtin variable OpVariable into entry block (PR #189958)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 06:27:23 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>

Move the OpVariable and decoration emission for builtin variables into the first MBB so that VReg definition dependencies remain valid across all BBs

---
Full diff: https://github.com/llvm/llvm-project/pull/189958.diff


2 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp (+8-2) 
- (modified) llvm/test/CodeGen/SPIRV/transcoding/OpGroupAsyncCopy.ll (+2-4) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index db5218ec73bb7..4c5c37e6d7ddc 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -518,11 +518,17 @@ static Register buildBuiltinVariableLoad(
       VariableType, MIRBuilder, SPIRV::StorageClass::Input);
   GR->assignSPIRVTypeToVReg(PtrType, NewRegister, MIRBuilder.getMF());
 
-  // Set up the global OpVariable with the necessary builtin decorations.
+  // Emit the OpVariable and its decorations into the first MBB to ensure
+  // VReg definition dependencies are valid across all MBBs.
+  MachineBasicBlock &EntryBB = MIRBuilder.getMF().front();
+  MachineIRBuilder FirstBlockBuilder;
+  FirstBlockBuilder.setMF(MIRBuilder.getMF());
+  FirstBlockBuilder.setMBB(EntryBB);
+
   Register Variable = GR->buildGlobalVariable(
       NewRegister, PtrType, getLinkStringForBuiltIn(BuiltinValue), nullptr,
       SPIRV::StorageClass::Input, nullptr, /* isConst= */ isConst, LinkageTy,
-      MIRBuilder, false);
+      FirstBlockBuilder, false);
 
   // Load the value from the global variable.
   Register LoadedRegister =
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAsyncCopy.ll b/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAsyncCopy.ll
index 3e68161105cc1..0c5b03895f579 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAsyncCopy.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/OpGroupAsyncCopy.ll
@@ -1,7 +1,5 @@
-; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
-
-; TODO: This test currently fails with LLVM_ENABLE_EXPENSIVE_CHECKS enabled
-; XFAIL: expensive_checks
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
 
 ; CHECK-SPIRV-DAG: %[[#]] = OpGroupAsyncCopy %[[#]] %[[#Scope:]]
 ; CHECK-SPIRV-DAG: %[[#Scope]] = OpConstant %[[#]]

``````````

</details>


https://github.com/llvm/llvm-project/pull/189958


More information about the llvm-commits mailing list