summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2011-08-24 20:18:38 +0000
committerNadav Rotem <nadav.rotem@intel.com>2011-08-24 20:18:38 +0000
commit365af6f17bf5b68490feef24c11d4e882bebfc8a (patch)
treee794f0bc68571007c3e8e3f0c138e0f134344234 /llvm/lib/Analysis/ConstantFolding.cpp
parentaf2f827a2cde88b5e7578999531539f24de47f26 (diff)
downloadbcm5719-llvm-365af6f17bf5b68490feef24c11d4e882bebfc8a.tar.gz
bcm5719-llvm-365af6f17bf5b68490feef24c11d4e882bebfc8a.zip
Implement Constant::isAllOnesValue(). Fix ConstantFolding to use the new api.
llvm-svn: 138469
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 7a8c703040c..df79849c3cf 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -45,16 +45,12 @@ 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() && !DestTy->isX86_MMXTy())
+ return Constant::getNullValue(DestTy);
+ if (C->isAllOnesValue() && !DestTy->isX86_MMXTy())
+ return Constant::getAllOnesValue(DestTy);
+
// The code below only handles casts to vectors currently.
VectorType *DestVTy = dyn_cast<VectorType>(DestTy);
if (DestVTy == 0)
@@ -68,6 +64,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);
OpenPOWER on IntegriCloud