aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2011-08-20 14:02:29 +0000
committerNadav Rotem <nadav.rotem@intel.com>2011-08-20 14:02:29 +0000
commit1c9fe0361b3f9f5c814ce761b97ecd11637a1d7d (patch)
tree615a65770d4508baa8eacb6ed524e6903e034643 /lib/Analysis
parent77c108241aae7d19d9d620b10ced8e783c7c8202 (diff)
Add constant folding support for bitcasts of splat vectors to integers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138206 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ConstantFolding.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index d74d7e806e..7a8c703040 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/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);