From: David Majnemer Date: Mon, 11 May 2015 05:04:22 +0000 (+0000) Subject: [InstCombine] Canonicalize single element array load X-Git-Tag: android-x86-7.1-r4~48349 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3101b1a432521d2d4a47967664bd0376a035c8c9;p=android-x86%2Fexternal-llvm.git [InstCombine] Canonicalize single element array load Use the element type instead of the aggregate type. Differential Revision: http://reviews.llvm.org/D9596 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236968 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 4ce5ad35549..1b0518654a0 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -518,6 +518,16 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) { } } + if (auto *AT = dyn_cast(T)) { + // If the array only have one element, we unpack. + if (AT->getNumElements() == 1) { + LoadInst *NewLoad = combineLoadToNewType(IC, LI, AT->getElementType(), + ".unpack"); + return IC.ReplaceInstUsesWith(LI, IC.Builder->CreateInsertValue( + UndefValue::get(T), NewLoad, 0, LI.getName())); + } + } + return nullptr; } diff --git a/test/Transforms/InstCombine/unpack-fca.ll b/test/Transforms/InstCombine/unpack-fca.ll index 58dfbe55162..759ffc694cf 100644 --- a/test/Transforms/InstCombine/unpack-fca.ll +++ b/test/Transforms/InstCombine/unpack-fca.ll @@ -55,6 +55,31 @@ body: ret { %A } %2 } +define [1 x %A] @loadArrayOfA() { +body: + %0 = tail call i8* @allocmemory(i64 32) + %1 = bitcast i8* %0 to [1 x %A]* +; CHECK-LABEL: loadArrayOfA +; CHECK: load %A__vtbl*, +; CHECK: insertvalue %A undef, %A__vtbl* {{.*}}, 0 +; CHECK: insertvalue [1 x %A] undef, %A {{.*}}, 0 + %2 = load [1 x %A], [1 x %A]* %1, align 8 + ret [1 x %A] %2 +} + +define { [1 x %A] } @loadStructOfArrayOfA() { +body: + %0 = tail call i8* @allocmemory(i64 32) + %1 = bitcast i8* %0 to { [1 x %A] }* +; CHECK-LABEL: loadStructOfArrayOfA +; CHECK: load %A__vtbl*, +; CHECK: insertvalue %A undef, %A__vtbl* {{.*}}, 0 +; CHECK: insertvalue [1 x %A] undef, %A {{.*}}, 0 +; CHECK: insertvalue { [1 x %A] } undef, [1 x %A] {{.*}}, 0 + %2 = load { [1 x %A] }, { [1 x %A] }* %1, align 8 + ret { [1 x %A] } %2 +} + define { %A } @structOfA() { body: %0 = tail call i8* @allocmemory(i64 32)