summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-09-25 22:46:21 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-09-25 22:46:21 +0000
commit051a318e67ae601c46b4fc7ceb5c5b0b605a296d (patch)
tree059ad472fc8b4edee48adf0dd4cea534eb43b547
parent289b5d7f02a442cb849d3762a78796d3355b02fc (diff)
downloadllvm-051a318e67ae601c46b4fc7ceb5c5b0b605a296d.tar.gz
llvm-051a318e67ae601c46b4fc7ceb5c5b0b605a296d.tar.bz2
llvm-051a318e67ae601c46b4fc7ceb5c5b0b605a296d.tar.xz
Don't drop the alignment on a memcpy intrinsic when producing a store. This is
only a missed optimization opportunity if the store is over-aligned, but a miscompile if the store's new type has a higher natural alignment than the memcpy did. Fixes PR13920! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164641 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/SROA.cpp5
-rw-r--r--test/Transforms/SROA/basictest.ll16
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp
index 1b3e8f9baf..04e350c25f 100644
--- a/lib/Transforms/Scalar/SROA.cpp
+++ b/lib/Transforms/Scalar/SROA.cpp
@@ -2272,8 +2272,9 @@ private:
getName(".insert"));
}
- Value *Store = IRB.CreateStore(Src, DstPtr, II.isVolatile());
- (void)Store;
+ StoreInst *Store = cast<StoreInst>(IRB.CreateStore(Src, DstPtr,
+ II.isVolatile()));
+ Store->setAlignment(II.getAlignment());
DEBUG(dbgs() << " to: " << *Store << "\n");
return !II.isVolatile();
}
diff --git a/test/Transforms/SROA/basictest.ll b/test/Transforms/SROA/basictest.ll
index 359a56a00d..f7a6e0e1e8 100644
--- a/test/Transforms/SROA/basictest.ll
+++ b/test/Transforms/SROA/basictest.ll
@@ -863,6 +863,7 @@ define void @test22() {
; CHECK-NOT: alloca
; CHECK: ret void
; PR13916
+
entry:
%A = alloca %test22.struct
br i1 undef, label %if.then, label %if.end
@@ -877,3 +878,18 @@ if.end: ; preds = %entry
%tmp2 = load %test22.struct* %A
ret void
}
+
+define void @test23(<2 x i64> %a, i16* %b) {
+; CHECK: @test23
+; CHECK: store {{.*}}, align 2
+; CHECK: ret void
+; PR13920
+
+entry:
+ %a.addr = alloca <2 x i64>, align 16
+ store <2 x i64> %a, <2 x i64>* %a.addr, align 16
+ %0 = bitcast i16* %b to i8*
+ %1 = bitcast <2 x i64>* %a.addr to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 16, i32 2, i1 false)
+ ret void
+}