summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-09-20 05:48:50 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-09-20 05:48:50 +0000
commit4a0345207732c6de918e2a9fafe8326a2ffb2cb0 (patch)
treeb0e489dd7efe1946eae60e1dce1598f4e58ded25 /llvm/lib/VMCore/ConstantFold.cpp
parentb1f2e101db658f93827a4e73c6d0ac3eed2d8f5a (diff)
downloadbcm5719-llvm-4a0345207732c6de918e2a9fafe8326a2ffb2cb0.tar.gz
bcm5719-llvm-4a0345207732c6de918e2a9fafe8326a2ffb2cb0.zip
Try turning icmp(bitcast(x), bitcast(y)) into icmp(bitcast(bitcast(x)), y) in
the hopes that the two bitcasts will merge. llvm-svn: 82371
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 8c65b563570..3f5c7efbb9a 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/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.
OpenPOWER on IntegriCloud