From: Hans Wennborg Date: Fri, 12 Feb 2016 01:42:38 +0000 (+0000) Subject: Merging r260587: X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=7a0ec464f16e761602ac9c4e1f610029c0346745 Merging r260587: ------------------------------------------------------------------------ r260587 | pete | 2016-02-11 13:10:40 -0800 (Thu, 11 Feb 2016) | 13 lines Set load alignment on aggregate loads. When optimizing a extractvalue(load), we generate a load from the aggregate type. This load didn't have alignment set and so would get the alignment of the type. This breaks when the type is packed and so the alignment should be lower. For example, loading { int, int } would give us alignment of 4, but the original load from this type may have an alignment of 1 if packed. Reviewed by David Majnemer Differential revision: http://reviews.llvm.org/D17158 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@260640 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 47406b9a163..dd2889de405 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -557,7 +557,8 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) { ConstantInt::get(IdxType, i), }; auto *Ptr = IC.Builder->CreateInBoundsGEP(ST, Addr, makeArrayRef(Indices), EltName); - auto *L = IC.Builder->CreateLoad(ST->getTypeAtIndex(i), Ptr, LoadName); + auto *L = IC.Builder->CreateAlignedLoad(Ptr, LI.getAlignment(), + LoadName); V = IC.Builder->CreateInsertValue(V, L, i); } diff --git a/test/Transforms/InstCombine/unpack-fca.ll b/test/Transforms/InstCombine/unpack-fca.ll index 9b8d1045749..435983924b7 100644 --- a/test/Transforms/InstCombine/unpack-fca.ll +++ b/test/Transforms/InstCombine/unpack-fca.ll @@ -136,3 +136,18 @@ define %B @structB(%B* %b.ptr) { %1 = load %B, %B* %b.ptr, align 8 ret %B %1 } + +%struct.S = type <{ i8, %struct.T }> +%struct.T = type { i32, i32 } + +; Make sure that we do not increase alignment of packed struct element +define i32 @packed_alignment(%struct.S* dereferenceable(9) %s) { +; CHECK-LABEL: packed_alignment +; CHECK-NEXT: %tv.elt1 = getelementptr inbounds %struct.S, %struct.S* %s, i64 0, i32 1, i32 1 +; CHECK-NEXT: %tv.unpack2 = load i32, i32* %tv.elt1, align 1 +; CHECK-NEXT: ret i32 %tv.unpack2 + %t = getelementptr inbounds %struct.S, %struct.S* %s, i32 0, i32 1 + %tv = load %struct.T, %struct.T* %t, align 1 + %v = extractvalue %struct.T %tv, 1 + ret i32 %v +}