[PATCH] D32608: SROA: Use correct address space when splitting loads (PR26154)

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 11:31:43 PDT 2017


hans created this revision.

escha reported this bug and proposed patch some time ago. Let's get it landed.


https://reviews.llvm.org/D32608

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/pr26154.ll


Index: test/Transforms/SROA/pr26154.ll
===================================================================
--- /dev/null
+++ test/Transforms/SROA/pr26154.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -sroa -S | FileCheck %s
+
+%struct.ham.1.29.35.67 = type <{ %struct.zot.0.28.34.66, [8 x i8], <4 x i32>, <3 x i8>, [12 x i8] }>
+%struct.zot.0.28.34.66 = type { <2 x i32> }
+
+; Just check that we don't crash due to invalid cast (PR26154).
+; CHECK: wombat1
+
+define void @wombat1(%struct.ham.1.29.35.67 addrspace(1)* %arg) {
+bb:
+  %tmp = alloca %struct.ham.1.29.35.67, align 16
+  %tmp1 = alloca %struct.ham.1.29.35.67, align 16
+  %tmp9 = getelementptr inbounds %struct.ham.1.29.35.67, %struct.ham.1.29.35.67* %tmp, i64 0, i32 3
+  %tmp10 = getelementptr inbounds %struct.ham.1.29.35.67, %struct.ham.1.29.35.67 addrspace(1)* %arg, i64 0, i32 3
+  %tmp11 = bitcast <3 x i8> addrspace(1)* %tmp10 to i32 addrspace(1)*
+  %tmp12 = load i32, i32 addrspace(1)* %tmp11, align 4
+  %tmp13 = bitcast <3 x i8>* %tmp9 to i32*
+  store i32 %tmp12, i32* %tmp13, align 16
+  %tmp19 = getelementptr inbounds %struct.ham.1.29.35.67, %struct.ham.1.29.35.67* %tmp1, i64 0, i32 2
+  %tmp20 = getelementptr inbounds %struct.ham.1.29.35.67, %struct.ham.1.29.35.67* %tmp, i64 0, i32 2
+  %tmp21 = bitcast <4 x i32>* %tmp19 to i8*
+  %tmp22 = bitcast <4 x i32>* %tmp20 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp21, i8* %tmp22, i64 20, i32 16, i1 false) #1
+  %tmp52 = getelementptr %struct.ham.1.29.35.67, %struct.ham.1.29.35.67* %tmp1, i64 0, i32 3
+  %tmp53 = load <3 x i8>, <3 x i8>* %tmp52, align 16
+  ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -3708,7 +3708,8 @@
         PLoad = IRB.CreateAlignedLoad(
             getAdjustedPtr(IRB, DL, LoadBasePtr,
                            APInt(DL.getPointerSizeInBits(), PartOffset),
-                           PartPtrTy, LoadBasePtr->getName() + "."),
+                           PartTy->getPointerTo(LI->getPointerAddressSpace()),
+                           LoadBasePtr->getName() + "."),
             getAdjustedAlignment(LI, PartOffset, DL), /*IsVolatile*/ false,
             LI->getName());
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32608.96954.patch
Type: text/x-patch
Size: 2387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170427/15bd2268/attachment.bin>


More information about the llvm-commits mailing list