diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 1b0518654a0..e74ab3c2afc 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -880,6 +880,15 @@ static bool unpackStoreToAggregate(InstCombiner &IC, StoreInst &SI) { } } + if (auto *AT = dyn_cast(T)) { + // If the array only have one element, we unpack. + if (AT->getNumElements() == 1) { + V = IC.Builder->CreateExtractValue(V, 0); + combineStoreToNewValue(IC, SI, V); + return true; + } + } + return false; } diff --git a/test/Transforms/InstCombine/unpack-fca.ll b/test/Transforms/InstCombine/unpack-fca.ll index 759ffc694cf..fc04b24a875 100644 --- a/test/Transforms/InstCombine/unpack-fca.ll +++ b/test/Transforms/InstCombine/unpack-fca.ll @@ -32,6 +32,26 @@ body: ret void } +define void @storeArrayOfA() { +body: + %0 = tail call i8* @allocmemory(i64 32) + %1 = bitcast i8* %0 to [1 x %A]* +; CHECK-LABEL: storeStructOfA +; CHECK: store %A__vtbl* @A__vtblZ + store [1 x %A] [%A { %A__vtbl* @A__vtblZ }], [1 x %A]* %1, align 8 + ret void +} + +define void @storeStructOfArrayOfA() { +body: + %0 = tail call i8* @allocmemory(i64 32) + %1 = bitcast i8* %0 to { [1 x %A] }* +; CHECK-LABEL: storeStructOfArrayOfA +; CHECK: store %A__vtbl* @A__vtblZ + store { [1 x %A] } { [1 x %A] [%A { %A__vtbl* @A__vtblZ }] }, { [1 x %A] }* %1, align 8 + ret void +} + define %A @loadA() { body: %0 = tail call i8* @allocmemory(i64 32)