diff options
author | Nadav Rotem <nadav.rotem@intel.com> | 2011-08-20 14:02:29 +0000 |
---|---|---|
committer | Nadav Rotem <nadav.rotem@intel.com> | 2011-08-20 14:02:29 +0000 |
commit | ad4a70ad3e25be09cc31187188db122e774ecdcf (patch) | |
tree | c368413b123eac27bce33fbf4903cfd8b6be167d /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | b76f385334405e6517ee60b5dfdf569ff4e94f1f (diff) | |
download | bcm5719-llvm-ad4a70ad3e25be09cc31187188db122e774ecdcf.tar.gz bcm5719-llvm-ad4a70ad3e25be09cc31187188db122e774ecdcf.zip |
Add constant folding support for bitcasts of splat vectors to integers.
llvm-svn: 138206
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index d74d7e806e6..7a8c703040c 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -46,7 +46,16 @@ using namespace llvm; static Constant *FoldBitCast(Constant *C, Type *DestTy, const TargetData &TD) { - // This only handles casts to vectors currently. + 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); + } + + // The code below only handles casts to vectors currently. VectorType *DestVTy = dyn_cast<VectorType>(DestTy); if (DestVTy == 0) return ConstantExpr::getBitCast(C, DestTy); @@ -59,7 +68,6 @@ 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); |