summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-23 06:57:37 +0000
committerChris Lattner <sabre@nondot.org>2009-10-23 06:57:37 +0000
commitccf1e847791a1d4dad5108e4147303440e85b8b1 (patch)
tree08b9a4494a0bb82356310f305a3e0dd944f9635b
parent59f94c01dd726f320382daded7f4e3bb09e81690 (diff)
downloadbcm5719-llvm-ccf1e847791a1d4dad5108e4147303440e85b8b1.tar.gz
bcm5719-llvm-ccf1e847791a1d4dad5108e4147303440e85b8b1.zip
teach libanalysis to simplify vector loads with bitcast sources. This
implements something out of Target/README.txt producing: _foo: ## @foo movl 4(%esp), %eax movapd LCPI1_0, %xmm0 movapd %xmm0, (%eax) ret $4 instead of: _foo: ## @foo movl 4(%esp), %eax movapd _b, %xmm0 mulpd LCPI1_0, %xmm0 addpd _a, %xmm0 movapd %xmm0, (%eax) ret $4 llvm-svn: 84942
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp20
-rw-r--r--llvm/test/Transforms/ConstProp/loads.ll10
2 files changed, 23 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 30305049614..214caeb92a0 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -210,24 +210,30 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
const TargetData &TD) {
- const Type *InitializerTy = cast<PointerType>(C->getType())->getElementType();
- const IntegerType *IntType = dyn_cast<IntegerType>(InitializerTy);
+ const Type *LoadTy = cast<PointerType>(C->getType())->getElementType();
+ const IntegerType *IntType = dyn_cast<IntegerType>(LoadTy);
// If this isn't an integer load we can't fold it directly.
if (!IntType) {
// If this is a float/double load, we can try folding it as an int32/64 load
- // and then bitcast the result. This can be useful for union cases.
+ // and then bitcast the result. This can be useful for union cases. Note
+ // that address spaces don't matter here since we're not going to result in
+ // an actual new load.
const Type *MapTy;
- if (InitializerTy->isFloatTy())
+ if (LoadTy->isFloatTy())
MapTy = Type::getInt32PtrTy(C->getContext());
- else if (InitializerTy->isDoubleTy())
+ else if (LoadTy->isDoubleTy())
MapTy = Type::getInt64PtrTy(C->getContext());
- else
+ else if (isa<VectorType>(LoadTy)) {
+ MapTy = IntegerType::get(C->getContext(),
+ TD.getTypeAllocSizeInBits(LoadTy));
+ MapTy = PointerType::getUnqual(MapTy);
+ } else
return 0;
C = ConstantExpr::getBitCast(C, MapTy);
if (Constant *Res = FoldReinterpretLoadFromConstPtr(C, TD))
- return ConstantExpr::getBitCast(Res, InitializerTy);
+ return ConstantExpr::getBitCast(Res, LoadTy);
return 0;
}
diff --git a/llvm/test/Transforms/ConstProp/loads.ll b/llvm/test/Transforms/ConstProp/loads.ll
index 3096ed347cb..f3e7f6a4b7b 100644
--- a/llvm/test/Transforms/ConstProp/loads.ll
+++ b/llvm/test/Transforms/ConstProp/loads.ll
@@ -77,3 +77,13 @@ define i128 @test9() {
; @test9
; CHECK: ret i128 112312312
}
+
+; vector load.
+define <2 x i64> @test10() {
+ %r = load <2 x i64>* bitcast({i64, i64}* @test3 to <2 x i64>*)
+ ret <2 x i64> %r
+
+; @test10
+; CHECK: ret <2 x i64> <i64 112312312, i64 0>
+}
+
OpenPOWER on IntegriCloud