[llvm] r236968 - [InstCombine] Canonicalize single element array load
David Majnemer
david.majnemer at gmail.com
Sun May 10 22:04:23 PDT 2015
Author: majnemer
Date: Mon May 11 00:04:22 2015
New Revision: 236968
URL: http://llvm.org/viewvc/llvm-project?rev=236968&view=rev
Log:
[InstCombine] Canonicalize single element array load
Use the element type instead of the aggregate type.
Differential Revision: http://reviews.llvm.org/D9596
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=236968&r1=236967&r2=236968&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Mon May 11 00:04:22 2015
@@ -518,6 +518,16 @@ static Instruction *unpackLoadToAggregat
}
}
+ if (auto *AT = dyn_cast<ArrayType>(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;
}
Modified: llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll?rev=236968&r1=236967&r2=236968&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/unpack-fca.ll Mon May 11 00:04:22 2015
@@ -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)
More information about the llvm-commits
mailing list