[PATCH] D144518: Preserve the address space for llvm.used and llvm.compiler.used global variables in GlobalOpt pass.

Nawal Copty via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 17:20:06 PDT 2023


nawalcopty updated this revision to Diff 509177.
nawalcopty added a comment.

Made changes as indicated by reviewers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144518/new/

https://reviews.llvm.org/D144518

Files:
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll


Index: llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll
===================================================================
--- llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll
+++ llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll
@@ -2,57 +2,33 @@
 ;; Check that Global Opt preserves address space of llvm.used and
 ;; llvm.compiler.used variables.
 
-; ModuleID = 'global-opt-addrspace.ll'
-source_filename = "device_global_internal_failure.cpp"
-target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
-target triple = "spir64-unknown-unknown"
-
 %struct.FakeDeviceGlobal = type { ptr addrspace(4) }
 %class.anon = type { i8 }
 
-$_ZTSZ4mainEUlvE_ = comdat any
+ at _ZM2C = internal addrspace(1) global %struct.FakeDeviceGlobal zeroinitializer, align 8
+ at _ZL1C = internal addrspace(1) global %struct.FakeDeviceGlobal zeroinitializer, align 8
 
- at _ZL1C = internal addrspace(1) global %struct.FakeDeviceGlobal zeroinitializer, align 8 #0
- at llvm.compiler.used = appending global [1 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4))], section "llvm.metadata"
+ at llvm.compiler.used = appending global [2 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZM2C to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4))]
 
-; CHECK: @llvm.compiler.used = appending global [1 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4))], section "llvm.metadata"
+; CHECK: @llvm.compiler.used = appending global [2 x ptr addrspace(4)] [ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZM2C to ptr addrspace(4))]
 
-; Function Attrs: convergent mustprogress noinline norecurse optnone
-define weak_odr dso_local spir_kernel void @_ZTSZ4mainEUlvE_() #1 comdat !kernel_arg_buffer_location !5 {
+define weak_odr dso_local void @foo() {
 entry:
-  %0 = alloca %class.anon, align 1
-  %1 = addrspacecast ptr %0 to ptr addrspace(4)
-  call spir_func void @_ZZ4mainENKUlvE_clEv(ptr addrspace(4) noundef align 1 dereferenceable_or_null(1) %1) #3
+  %A = alloca %class.anon, align 1
+  %A.addrspacecast = addrspacecast ptr %A to ptr addrspace(4)
+  call void @bar(ptr addrspace(4) noundef align 1 dereferenceable_or_null(1) %A.addrspacecast)
   ret void
 }
 
-; Function Attrs: convergent mustprogress noinline norecurse nounwind optnone
-define internal spir_func void @_ZZ4mainENKUlvE_clEv(ptr addrspace(4) noundef align 1 dereferenceable_or_null(1) %this) #2 align 2 {
+define internal void @bar(ptr addrspace(4) noundef align 1 dereferenceable_or_null(1) %this) align 2 {
 entry:
   %this.addr = alloca ptr addrspace(4), align 8
   %this.addr.ascast = addrspacecast ptr %this.addr to ptr addrspace(4)
   store ptr addrspace(4) %this, ptr addrspace(4) %this.addr.ascast, align 8
-  %this1 = load ptr addrspace(4), ptr addrspace(4) %this.addr.ascast, align 8
-  %0 = load ptr addrspace(4), ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4)), align 8
-  store i32 42, ptr addrspace(4) %0, align 4
+  %v1 = load ptr addrspace(4), ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZM2C to ptr addrspace(4)), align 8
+  store i32 42, ptr addrspace(4) %v1, align 4
+  %v2 = load ptr addrspace(4), ptr addrspace(4) addrspacecast (ptr addrspace(1) @_ZL1C to ptr addrspace(4)), align 8
+  store i32 42, ptr addrspace(4) %v2, align 4
   ret void
 }
 
-declare dso_local spir_func i32 @_Z18__spirv_ocl_printfPU3AS2Kcz(ptr addrspace(2), ...)
-
-attributes #0 = { "sycl-unique-id"="c5b4ae0b52852573____ZL1C" }
-attributes #1 = { convergent mustprogress noinline norecurse optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="device_global_internal_failure.cpp" "uniform-work-group-size"="true" }
-attributes #2 = { convergent mustprogress noinline norecurse nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-attributes #3 = { convergent }
-
-!llvm.module.flags = !{!0, !1}
-!opencl.spir.version = !{!2}
-!spirv.Source = !{!3}
-!llvm.ident = !{!4}
-
-!0 = !{i32 1, !"wchar_size", i32 4}
-!1 = !{i32 7, !"frame-pointer", i32 2}
-!2 = !{i32 1, i32 2}
-!3 = !{i32 4, i32 100000}
-!4 = !{!"clang version 15.0.0 (https://github.com/intel/llvm.git 537e51b08b74438ed64eb7de6e254922e8ddeaa0)"}
-!5 = !{}
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2119,8 +2119,8 @@
   unsigned ElemAddrSpace = 0;
   const Type *UsedArrayType = V.getValueType();
 
-  if (const auto *VAT = dyn_cast<ArrayType>(UsedArrayType))
-    if (const auto *VEPT = dyn_cast<PointerType>(VAT->getArrayElementType()))
+  if (const auto *VAT = cast<ArrayType>(UsedArrayType))
+    if (const auto *VEPT = cast<PointerType>(VAT->getArrayElementType()))
       ElemAddrSpace = VEPT->getAddressSpace();
 
   // Type of pointer to the array of pointers.
@@ -2132,6 +2132,7 @@
       = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, Int8PtrTy);
     UsedArray.push_back(Cast);
   }
+
   // Sort to get deterministic order.
   array_pod_sort(UsedArray.begin(), UsedArray.end(), compareNames);
   ArrayType *ATy = ArrayType::get(Int8PtrTy, UsedArray.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144518.509177.patch
Type: text/x-patch
Size: 5540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230329/900d17de/attachment.bin>


More information about the llvm-commits mailing list