summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-25 22:04:58 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-25 22:04:58 +0000
commit62611fd3f70d32e16899d3783784be11e3a9c344 (patch)
tree7ce56db4c7288a607e8be2645e1714bf8285f55e /llvm/lib/Analysis/InstructionSimplify.cpp
parentefc4066b47027d00b43fffef9b8d780c132a1114 (diff)
downloadbcm5719-llvm-62611fd3f70d32e16899d3783784be11e3a9c344.tar.gz
bcm5719-llvm-62611fd3f70d32e16899d3783784be11e3a9c344.zip
[InstSimplify] Add support for bitcasts
BitCasts of BitCasts can be folded away as can BitCasts which don't change the type of the operand. llvm-svn: 276698
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 981fb976c02..8fde9c7281d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -70,6 +70,7 @@ static Value *SimplifyCmpInst(unsigned, Value *, Value *, const Query &,
static Value *SimplifyOrInst(Value *, Value *, const Query &, unsigned);
static Value *SimplifyXorInst(Value *, Value *, const Query &, unsigned);
static Value *SimplifyTruncInst(Value *, Type *, const Query &, unsigned);
+static Value *SimplifyBitCastInst(Value *, Type *, const Query &, unsigned);
/// For a boolean type, or a vector of boolean type, return false, or
/// a vector with every element false, as appropriate for the type.
@@ -3810,6 +3811,30 @@ Value *llvm::SimplifyTruncInst(Value *Op, Type *Ty, const DataLayout &DL,
RecursionLimit);
}
+static Value *SimplifyBitCastInst(Value *Op, Type *Ty, const Query &Q, unsigned) {
+ if (auto *C = dyn_cast<Constant>(Op))
+ return ConstantFoldCastOperand(Instruction::BitCast, C, Ty, Q.DL);
+
+ // bitcast x -> x
+ if (Op->getType() == Ty)
+ return Op;
+
+ // bitcast(bitcast x) -> x
+ if (auto *BC = dyn_cast<BitCastInst>(Op))
+ if (BC->getOperand(0)->getType() == Ty)
+ return BC->getOperand(0);
+
+ return nullptr;
+}
+
+Value *llvm::SimplifyBitCastInst(Value *Op, Type *Ty, const DataLayout &DL,
+ const TargetLibraryInfo *TLI,
+ const DominatorTree *DT, AssumptionCache *AC,
+ const Instruction *CxtI) {
+ return ::SimplifyBitCastInst(Op, Ty, Query(DL, TLI, DT, AC, CxtI),
+ RecursionLimit);
+}
+
//=== Helper functions for higher up the class hierarchy.
/// Given operands for a BinaryOperator, see if we can fold the result.
@@ -4280,6 +4305,10 @@ Value *llvm::SimplifyInstruction(Instruction *I, const DataLayout &DL,
Result =
SimplifyTruncInst(I->getOperand(0), I->getType(), DL, TLI, DT, AC, I);
break;
+ case Instruction::BitCast:
+ Result =
+ SimplifyBitCastInst(I->getOperand(0), I->getType(), DL, TLI, DT, AC, I);
+ break;
}
// In general, it is possible for computeKnownBits to determine all bits in a
OpenPOWER on IntegriCloud