[llvm] [SPIR-V] Fix an undefined behaviour in the SPIRV emit-intrinsics pass (PR #123620)

Vyacheslav Levytskyy via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 06:20:04 PST 2025


https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/123620

Adding SPIRV to LLVM_ALL_TARGETS (https://github.com/llvm/llvm-project/pull/119653) revealed a series of minor compilation problems and sanitizer complaints. This PR is to address the problem of the undefined behaviour in the SPIRV emit-intrinsics pass. 

I can see no more SPIR-V Builder-related fails in sanitizers, checked locally as:

```
mkdir sanitizer
cd sanitizer/
git clone https://github.com/llvm/llvm-zorg.git
BUILDBOT_MONO_REPO_PATH=/path-to-the-fixed-locally-sources/llvm-project llvm-zorg/zorg/buildbot/builders/sanitizers/buildbot_fast.sh
```

>From b16900fe3ab9974792bf8d3cdeb83de09e236dc1 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Mon, 20 Jan 2025 06:17:02 -0800
Subject: [PATCH] Fix an undefined behaviour in the SPIRV emit-intrinsics pass

---
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 1c1acd29ee0e6a..c77b9af4652b95 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -2475,8 +2475,10 @@ void SPIRVEmitIntrinsics::parseFunDeclarations(Module &M) {
     if (DemangledName.empty())
       continue;
     // allow only OpGroupAsyncCopy use case at the moment
-    auto [Grp, Opcode, ExtNo] =
-        SPIRV::mapBuiltinToOpcode(DemangledName, InstrSet);
+    auto [Grp, Opcode, ExtNo] = SPIRV::mapBuiltinToOpcode(
+        DemangledName, TM->getSubtarget<SPIRVSubtarget>(F).isOpenCLEnv()
+                           ? SPIRV::InstructionSet::OpenCL_std
+                           : SPIRV::InstructionSet::GLSL_std_450);
     if (Opcode != SPIRV::OpGroupAsyncCopy)
       continue;
     // find pointer arguments



More information about the llvm-commits mailing list