[llvm] fix producing multiple identical opaque pointer types (PR #79060)

Vyacheslav Levytskyy via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 14:38:48 PST 2024


https://github.com/VyacheslavLevytskyy updated https://github.com/llvm/llvm-project/pull/79060

>From d6cf6a5e2701de746ed8e55f93d595031315866e Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Mon, 22 Jan 2024 12:33:37 -0800
Subject: [PATCH 1/3] fix producing multiple identical opaque pointer types

---
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp     |  9 +++++----
 llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 6c009b9e8ddefac..f9581390c28b9e1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -716,13 +716,14 @@ SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
         ForwardPointerTypes[PType] = getOpTypeForwardPointer(SC, MIRBuilder);
       return ForwardPointerTypes[PType];
     }
-    Register Reg(0);
     // If we have forward pointer associated with this type, use its register
     // operand to create OpTypePointer.
-    if (ForwardPointerTypes.contains(PType))
-      Reg = getSPIRVTypeID(ForwardPointerTypes[PType]);
+    if (ForwardPointerTypes.contains(PType)) {
+      Register Reg = getSPIRVTypeID(ForwardPointerTypes[PType]);
+      return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
+    }
 
-    return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
+    return getOrCreateSPIRVPointerType(SpvElementType, MIRBuilder, SC);
   }
   llvm_unreachable("Unable to convert LLVM type to SPIRVType");
 }
diff --git a/llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll b/llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll
new file mode 100644
index 000000000000000..f5ef3a4d11dd0ee
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll
@@ -0,0 +1,15 @@
+; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+
+; CHECK: %[[TyInt8:.*]] = OpTypeInt 8 0
+; CHECK: %[[TyInt8Ptr:.*]] = OpTypePointer {{[a-zA-Z]+}} %[[TyInt8]]
+; CHECK: %[[TyStruct:.*]] = OpTypeStruct %[[TyInt8Ptr]] %[[TyInt8Ptr]]
+; CHECK: %[[ConstStruct:.*]] = OpConstantComposite %[[TyStruct]] %[[ConstField:.*]] %[[ConstField]]
+; CHECK: %[[TyStructPtr:.*]] = OpTypePointer {{[a-zA-Z]+}} %[[TyStruct]]
+; CHECK: OpVariable %[[TyStructPtr]] {{[a-zA-Z]+}} %[[ConstStruct]]
+
+ at a = addrspace(1) constant i32 123
+ at struct = addrspace(1) global {ptr addrspace(1), ptr addrspace(1)} { ptr addrspace(1) @a, ptr addrspace(1) @a }
+
+define spir_kernel void @foo() {
+  ret void
+}

>From c4ff535674662defefd234e4c86154504372d5e8 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Tue, 23 Jan 2024 02:27:55 -0800
Subject: [PATCH 2/3] remove XFAIL mark as the test doesn't fail after the
 change in opaque pointer types geenration

---
 .../test/CodeGen/SPIRV/opencl/device_execution/execute_block.ll | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/test/CodeGen/SPIRV/opencl/device_execution/execute_block.ll b/llvm/test/CodeGen/SPIRV/opencl/device_execution/execute_block.ll
index 1df72dc734dbd97..562f5c7b6826e10 100644
--- a/llvm/test/CodeGen/SPIRV/opencl/device_execution/execute_block.ll
+++ b/llvm/test/CodeGen/SPIRV/opencl/device_execution/execute_block.ll
@@ -1,7 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
 
-; TODO(#60133): Requires updates following opaque pointer migration.
-; XFAIL: *
 ; REQUIRES: asserts
 
 ; CHECK: %[[#bool:]] = OpTypeBool

>From 9fd3219de97800d0eef2a734ae17909f53e76ccc Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Thu, 25 Jan 2024 14:38:31 -0800
Subject: [PATCH 3/3] change underscores to dashes in the name of the test and
 move it to another folder

---
 .../struct-opaque-pointers.ll}                                   | 1 +
 1 file changed, 1 insertion(+)
 rename llvm/test/CodeGen/SPIRV/{struct_opaque_pointers.ll => pointers/struct-opaque-pointers.ll} (86%)

diff --git a/llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll b/llvm/test/CodeGen/SPIRV/pointers/struct-opaque-pointers.ll
similarity index 86%
rename from llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll
rename to llvm/test/CodeGen/SPIRV/pointers/struct-opaque-pointers.ll
index f5ef3a4d11dd0ee..86f5f5bf24f5be2 100644
--- a/llvm/test/CodeGen/SPIRV/struct_opaque_pointers.ll
+++ b/llvm/test/CodeGen/SPIRV/pointers/struct-opaque-pointers.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
 
 ; CHECK: %[[TyInt8:.*]] = OpTypeInt 8 0
 ; CHECK: %[[TyInt8Ptr:.*]] = OpTypePointer {{[a-zA-Z]+}} %[[TyInt8]]



More information about the llvm-commits mailing list