aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-29 04:06:09 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-29 04:06:09 +0000
commite4218cf11e163aaa89ef08619af2053c91985ed6 (patch)
tree54c8334075373e4007705f88a6bfaf7c55f91455 /llvm/lib/Analysis/ConstantFolding.cpp
parent09d4f177fc28f603ad53769ceab4300270bf6654 (diff)
downloadllvm-e4218cf11e163aaa89ef08619af2053c91985ed6.zip
llvm-e4218cf11e163aaa89ef08619af2053c91985ed6.tar.gz
llvm-e4218cf11e163aaa89ef08619af2053c91985ed6.tar.bz2
[ConstantFolding] Fold bitcasts of vectors w/ undef elements
An undef vector element can be treated as if it had any value. Folding such a vector element to 0 in a bitcast can open up further folding opportunities. llvm-svn: 277104
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 010f5d6..60b94a9 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -90,6 +90,11 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
else
Element = C->getAggregateElement(i);
+ if (Element && isa<UndefValue>(Element)) {
+ Result <<= BitShift;
+ continue;
+ }
+
auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
if (!ElementCI)
return ConstantExpr::getBitCast(C, DestTy);
@@ -180,7 +185,11 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
Constant *Elt = Zero;
unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
for (unsigned j = 0; j != Ratio; ++j) {
- Constant *Src = dyn_cast<ConstantInt>(C->getAggregateElement(SrcElt++));
+ Constant *Src = C->getAggregateElement(SrcElt++);
+ if (Src && isa<UndefValue>(Src))
+ Src = Constant::getNullValue(SrcEltTy);
+ else
+ Src = dyn_cast_or_null<ConstantInt>(Src);
if (!Src) // Reject constantexpr elements.
return ConstantExpr::getBitCast(C, DestTy);
@@ -206,7 +215,7 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
// Loop over each source value, expanding into multiple results.
for (unsigned i = 0; i != NumSrcElt; ++i) {
- auto *Src = dyn_cast<ConstantInt>(C->getAggregateElement(i));
+ auto *Src = dyn_cast_or_null<ConstantInt>(C->getAggregateElement(i));
if (!Src) // Reject constantexpr elements.
return ConstantExpr::getBitCast(C, DestTy);