diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 05:48:50 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 05:48:50 +0000 |
commit | 55a722bf6a08c684e49f5b56301bfc66d6dc9fd4 (patch) | |
tree | 08ace6b453257738cf3bdaffb9a73c3dee86a84c /lib/VMCore | |
parent | 043b8b5bb2a54133549fbf08e78345a5d086328a (diff) | |
download | external_llvm-55a722bf6a08c684e49f5b56301bfc66d6dc9fd4.zip external_llvm-55a722bf6a08c684e49f5b56301bfc66d6dc9fd4.tar.gz external_llvm-55a722bf6a08c684e49f5b56301bfc66d6dc9fd4.tar.bz2 |
Try turning icmp(bitcast(x), bitcast(y)) into icmp(bitcast(bitcast(x)), y) in
the hopes that the two bitcasts will merge.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82371 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 8c65b56..3f5c7ef 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1627,6 +1627,16 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, if (Result != -1) return ConstantInt::get(Type::getInt1Ty(Context), Result); + // If the right hand side is a bitcast, try using its inverse to simplify + // it by moving it to the left hand side. + if (ConstantExpr *CE2 = dyn_cast<ConstantExpr>(C2)) { + if (CE2->getOpcode() == Instruction::BitCast) { + Constant *CE2Op0 = CE2->getOperand(0); + Constant *Inverse = ConstantExpr::getBitCast(C1, CE2Op0->getType()); + return ConstantExpr::getICmp(pred, Inverse, CE2Op0); + } + } + if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) { // If C2 is a constant expr and C1 isn't, flip them around and fold the // other way if possible. |