aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2011-08-23 17:48:43 +0000
committerNadav Rotem <nadav.rotem@intel.com>2011-08-23 17:48:43 +0000
commitc78e6607b54a7e1e63ac44a17197d0ea15302bb3 (patch)
treeec227a06f839f1360036b25b4a7800f89410e87e /llvm/lib/Analysis/ConstantFolding.cpp
parent9b7bd15d0b865a1fddb3e32254dcd4ef4068b145 (diff)
downloadllvm-c78e6607b54a7e1e63ac44a17197d0ea15302bb3.zip
llvm-c78e6607b54a7e1e63ac44a17197d0ea15302bb3.tar.gz
llvm-c78e6607b54a7e1e63ac44a17197d0ea15302bb3.tar.bz2
Address Duncan's CR request:
1. Cleanup the tests in ConstantFolding.cpp 2. Implement isAllOnes for Constant, ConstantFP, ConstantVector llvm-svn: 138340
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 7a8c703..0eacaf8 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -45,15 +45,9 @@ using namespace llvm;
/// ConstantExpr if unfoldable.
static Constant *FoldBitCast(Constant *C, Type *DestTy,
const TargetData &TD) {
-
- ConstantVector *CV = dyn_cast<ConstantVector>(C);
- IntegerType *IntVTy = dyn_cast<IntegerType>(DestTy);
- // When casting vectors to scalar integers, catch the
- // obvious splat cases.
- if (IntVTy && CV) {
- if (CV->isNullValue()) return ConstantInt::getNullValue(IntVTy);
- if (CV->isAllOnesValue()) return ConstantInt::getAllOnesValue(IntVTy);
- }
+ // Catch the obvious splat cases.
+ if (C->isNullValue()) return Constant::getNullValue(DestTy);
+ if (C->isAllOnesValue()) return Constant::getAllOnesValue(DestTy);
// The code below only handles casts to vectors currently.
VectorType *DestVTy = dyn_cast<VectorType>(DestTy);
@@ -68,6 +62,7 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
}
// If this is a bitcast from constant vector -> vector, fold it.
+ ConstantVector *CV = dyn_cast<ConstantVector>(C);
if (CV == 0)
return ConstantExpr::getBitCast(C, DestTy);