diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-09-29 10:41:21 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-09-29 10:41:21 +0000 |
commit | b67c9a5b0295faaab40c6c64c433ab679d225a70 (patch) | |
tree | 9ffd2d4f59d8e308ad39667f9335e8031bcecade /test/Transforms/SROA/alignment.ll | |
parent | 454627252b1cc43e81949d41eb20e9ea9560da58 (diff) | |
download | external_llvm-b67c9a5b0295faaab40c6c64c433ab679d225a70.zip external_llvm-b67c9a5b0295faaab40c6c64c433ab679d225a70.tar.gz external_llvm-b67c9a5b0295faaab40c6c64c433ab679d225a70.tar.bz2 |
Fix a somewhat surprising miscompile where code relying on an ABI
alignment could lose it due to the alloca type moving down to a much
smaller alignment guarantee.
Now SROA will actively compute a proper alignment, factoring the target
data, any explicit alignment, and the offset within the struct. This
will in some cases lower the alignment requirements, but when we lower
them below those of the type, we drop the alignment entirely to give
freedom to the code generator to align it however is convenient.
Thanks to Duncan for the lovely test case that pinned this down. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164891 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/SROA/alignment.ll')
-rw-r--r-- | test/Transforms/SROA/alignment.ll | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/test/Transforms/SROA/alignment.ll b/test/Transforms/SROA/alignment.ll index 953f511..02a6755 100644 --- a/test/Transforms/SROA/alignment.ll +++ b/test/Transforms/SROA/alignment.ll @@ -30,7 +30,7 @@ entry: define void @test2() { ; CHECK: @test2 -; CHECK: alloca i16, align 2 +; CHECK: alloca i16 ; CHECK: load i8* %{{.*}}, align 1 ; CHECK: store i8 42, i8* %{{.*}}, align 1 ; CHECK: ret void @@ -62,3 +62,24 @@ entry: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %bptr, i8* %aaptr, i32 16, i32 2, i1 false) ret void } + +define void @test3(i8* %x) { +; Test that when we promote an alloca to a type with lower ABI alignment, we +; provide the needed explicit alignment that code using the alloca may be +; expecting. However, also check that any offset within an alloca can in turn +; reduce the alignment. +; CHECK: @test3 +; CHECK: alloca [22 x i8], align 8 +; CHECK: alloca [18 x i8], align 2 +; CHECK: ret void + +entry: + %a = alloca { i8*, i8*, i8* } + %b = alloca { i8*, i8*, i8* } + %a_raw = bitcast { i8*, i8*, i8* }* %a to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a_raw, i8* %x, i32 22, i32 8, i1 false) + %b_raw = bitcast { i8*, i8*, i8* }* %b to i8* + %b_gep = getelementptr i8* %b_raw, i32 6 + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b_gep, i8* %x, i32 18, i32 2, i1 false) + ret void +} |