diff options
author | Nicola Zaghen <nicola.zaghen@imgtec.com> | 2018-10-30 11:15:04 +0000 |
---|---|---|
committer | Nicola Zaghen <nicola.zaghen@imgtec.com> | 2018-10-30 11:15:04 +0000 |
commit | f96383c99e51b793247b4c82fc4fe1c62f6b28d3 (patch) | |
tree | 1c48f203ab3f4f05b207cf4d450aac6afa9fbba7 | |
parent | b3a14208ac3cdb27588992a7c988b02c981c0586 (diff) | |
download | bcm5719-llvm-f96383c99e51b793247b4c82fc4fe1c62f6b28d3.tar.gz bcm5719-llvm-f96383c99e51b793247b4c82fc4fe1c62f6b28d3.zip |
[SROA] Use offset sizes from the DataLayout instead of the pointer siezes.
This fixes an assertion when constant folding a GEP when the part of the offset
was in i32 (IndexSize, as per DataLayout) and part in the i64 (PointerSize) in
the newly created test case.
Differential Revision: https://reviews.llvm.org/D52609
llvm-svn: 345585
-rw-r--r-- | llvm/lib/Transforms/Scalar/SROA.cpp | 12 | ||||
-rw-r--r-- | llvm/test/Transforms/SROA/pointer-offset-size.ll | 29 |
2 files changed, 35 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 0f43ee6bbd7..a8b9ee56639 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -1400,8 +1400,8 @@ static Value *getNaturalGEPWithType(IRBuilderTy &IRB, const DataLayout &DL, if (Ty == TargetTy) return buildGEP(IRB, BasePtr, Indices, NamePrefix); - // Pointer size to use for the indices. - unsigned PtrSize = DL.getPointerTypeSizeInBits(BasePtr->getType()); + // Offset size to use for the indices. + unsigned OffsetSize = DL.getIndexTypeSizeInBits(BasePtr->getType()); // See if we can descend into a struct and locate a field with the correct // type. @@ -1413,7 +1413,7 @@ static Value *getNaturalGEPWithType(IRBuilderTy &IRB, const DataLayout &DL, if (ArrayType *ArrayTy = dyn_cast<ArrayType>(ElementTy)) { ElementTy = ArrayTy->getElementType(); - Indices.push_back(IRB.getIntN(PtrSize, 0)); + Indices.push_back(IRB.getIntN(OffsetSize, 0)); } else if (VectorType *VectorTy = dyn_cast<VectorType>(ElementTy)) { ElementTy = VectorTy->getElementType(); Indices.push_back(IRB.getInt32(0)); @@ -2377,7 +2377,7 @@ private: #endif return getAdjustedPtr(IRB, DL, &NewAI, - APInt(DL.getPointerTypeSizeInBits(PointerTy), Offset), + APInt(DL.getIndexTypeSizeInBits(PointerTy), Offset), PointerTy, #ifndef NDEBUG Twine(OldName) + "." @@ -2899,8 +2899,8 @@ private: unsigned OtherAS = OtherPtrTy->getPointerAddressSpace(); // Compute the relative offset for the other pointer within the transfer. - unsigned IntPtrWidth = DL.getPointerSizeInBits(OtherAS); - APInt OtherOffset(IntPtrWidth, NewBeginOffset - BeginOffset); + unsigned OffsetWidth = DL.getIndexSizeInBits(OtherAS); + APInt OtherOffset(OffsetWidth, NewBeginOffset - BeginOffset); unsigned OtherAlign = IsDest ? II.getSourceAlignment() : II.getDestAlignment(); OtherAlign = MinAlign(OtherAlign ? OtherAlign : 1, diff --git a/llvm/test/Transforms/SROA/pointer-offset-size.ll b/llvm/test/Transforms/SROA/pointer-offset-size.ll new file mode 100644 index 00000000000..c632c37988b --- /dev/null +++ b/llvm/test/Transforms/SROA/pointer-offset-size.ll @@ -0,0 +1,29 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -sroa -S | FileCheck %s +target datalayout = "e-p:64:64:64:32" + +%struct.test = type { %struct.basic, %struct.basic } +%struct.basic = type { i16, i8 } + +define i16 @test(%struct.test* %ts2.i) { +; CHECK-LABEL: @test( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[S_SROA_0:%.*]] = alloca [3 x i8], align 2 +; CHECK-NEXT: [[S_SROA_0_0__SROA_CAST:%.*]] = bitcast %struct.test* [[TS2_I:%.*]] to i8* +; CHECK-NEXT: [[S_SROA_0_0__SROA_IDX:%.*]] = getelementptr inbounds [3 x i8], [3 x i8]* [[S_SROA_0]], i32 0, i32 0 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[S_SROA_0_0__SROA_CAST]], i8* align 2 [[S_SROA_0_0__SROA_IDX]], i32 3, i1 false) +; CHECK-NEXT: [[X1_I_I:%.*]] = getelementptr inbounds [[STRUCT_TEST:%.*]], %struct.test* [[TS2_I]], i32 0, i32 0, i32 0 +; CHECK-NEXT: [[TMP0:%.*]] = load i16, i16* [[X1_I_I]] +; CHECK-NEXT: ret i16 [[TMP0]] +; +entry: + %s = alloca %struct.test + %0 = bitcast %struct.test* %ts2.i to i8* + %1 = bitcast %struct.test* %s to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 3, i1 false) + %x1.i.i = getelementptr inbounds %struct.test, %struct.test* %ts2.i, i32 0, i32 0, i32 0 + %2 = load i16, i16* %x1.i.i + ret i16 %2 +} + +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) |