[llvm] 8a4551b - [Attributor][FIX] Use right address space to avoid assertion

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 27 16:22:51 PDT 2021


Author: Johannes Doerfert
Date: 2021-10-27T18:22:37-05:00
New Revision: 8a4551b893b780db55ce25acc8eaf7a2921ed766

URL: https://github.com/llvm/llvm-project/commit/8a4551b893b780db55ce25acc8eaf7a2921ed766
DIFF: https://github.com/llvm/llvm-project/commit/8a4551b893b780db55ce25acc8eaf7a2921ed766.diff

LOG: [Attributor][FIX] Use right address space to avoid assertion

When we strip and accumulate constant offsets we need to pick the right
address space such that the offset APInt has the right bit width.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D112544

Added: 
    llvm/test/Transforms/OpenMP/attributor_pointer_offset_crash.ll

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 4cf5cad9fdeb..c89bda73a263 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1224,7 +1224,11 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
         }
 
         // Check if the PHI operand is not dependent on the PHI itself.
-        APInt Offset(DL.getIndexTypeSizeInBits(AssociatedValue.getType()), 0);
+        // TODO: This is not great as we look at the pointer type. However, it
+        // is unclear where the Offset size comes from with typeless pointers.
+        APInt Offset(
+            DL.getIndexSizeInBits(CurPtr->getType()->getPointerAddressSpace()),
+            0);
         if (&AssociatedValue == CurPtr->stripAndAccumulateConstantOffsets(
                                     DL, Offset, /* AllowNonInbounds */ true)) {
           if (Offset != PtrOI.Offset) {

diff  --git a/llvm/test/Transforms/OpenMP/attributor_pointer_offset_crash.ll b/llvm/test/Transforms/OpenMP/attributor_pointer_offset_crash.ll
new file mode 100644
index 000000000000..080ae279c2a5
--- /dev/null
+++ b/llvm/test/Transforms/OpenMP/attributor_pointer_offset_crash.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -S -passes=openmp-opt
+
+; Verify the address space cast doesn't cause a crash
+
+target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7"
+
+%"struct.(anonymous namespace)::TeamStateTy" = type { %"struct.(anonymous namespace)::ICVStateTy", i32, i8* }
+%"struct.(anonymous namespace)::ICVStateTy" = type { i32, i32, i32, i32, i32, i32 }
+%"struct.(anonymous namespace)::ThreadStateTy" = type { %"struct.(anonymous namespace)::ICVStateTy", %"struct.(anonymous namespace)::ThreadStateTy"* }
+
+ at _ZN12_GLOBAL__N_19TeamStateE = internal addrspace(3) global %"struct.(anonymous namespace)::TeamStateTy" undef, align 8
+
+define internal i8* @__kmpc_alloc_shared() {
+lor.lhs.false.i.i:
+  br i1 false, label %_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i, label %if.then.i44.i.i
+
+if.then.i44.i.i:                                  ; preds = %lor.lhs.false.i.i
+  br label %_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i
+
+_ZN4_OMP5state8lookup32ENS0_9ValueKindEb.exit.i:  ; preds = %if.then.i44.i.i, %lor.lhs.false.i.i
+  %.pn.i45.i.i = phi i8* [ null, %if.then.i44.i.i ], [ addrspacecast (i8 addrspace(3)* bitcast (%"struct.(anonymous namespace)::TeamStateTy" addrspace(3)* @_ZN12_GLOBAL__N_19TeamStateE to i8 addrspace(3)*) to i8*), %lor.lhs.false.i.i ]
+  %retval.0.in.i.i.i = getelementptr inbounds i8, i8* %.pn.i45.i.i, i64 4
+  %retval.0.i46.i.i = bitcast i8* %retval.0.in.i.i.i to i32*
+  %0 = load i32, i32* %retval.0.i46.i.i, align 4
+  ret i8* null
+}
+
+!llvm.module.flags = !{!0, !1}
+
+!0 = !{i32 7, !"openmp", i32 50}
+!1 = !{i32 7, !"openmp-device", i32 50}


        


More information about the llvm-commits mailing list