From 365af6f17bf5b68490feef24c11d4e882bebfc8a Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Wed, 24 Aug 2011 20:18:38 +0000 Subject: Implement Constant::isAllOnesValue(). Fix ConstantFolding to use the new api. llvm-svn: 138469 --- llvm/lib/Analysis/ConstantFolding.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 7a8c703..df79849 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(C); - IntegerType *IntVTy = dyn_cast(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(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(C); if (CV == 0) return ConstantExpr::getBitCast(C, DestTy); -- cgit v1.1