summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-03-26 01:44:11 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-03-26 01:44:11 +0000
commitdf9b4adb821a5144ccafcb5840be92eb3d2e5c70 (patch)
tree4772de68fe5a36f226b5aff0fa0b276abf9ce946 /llvm/lib/Analysis/InstructionSimplify.cpp
parent5fa0caafc0ccfb45c879219d4fb6962018e51b89 (diff)
downloadbcm5719-llvm-df9b4adb821a5144ccafcb5840be92eb3d2e5c70.tar.gz
bcm5719-llvm-df9b4adb821a5144ccafcb5840be92eb3d2e5c70.zip
Use the new range metadata in computeMaskedBits and add a new optimization to
instruction simplify that lets us remove an and when loding a boolean value. llvm-svn: 153423
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 16e7a726595..28400b08b1c 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1370,6 +1370,21 @@ static Value *SimplifyAndInst(Value *Op0, Value *Op1, const Query &Q,
return Op1;
}
+ unsigned Bitwidth = Op1->getType()->getScalarSizeInBits();
+ APInt DemandedMask = APInt::getAllOnesValue(Bitwidth);
+ APInt KnownZero0 = APInt::getNullValue(Bitwidth);
+ APInt KnownOne0 = APInt::getNullValue(Bitwidth);
+ ComputeMaskedBits(Op0, DemandedMask, KnownZero0, KnownOne0);
+ APInt KnownZero1 = APInt::getNullValue(Bitwidth);
+ APInt KnownOne1 = APInt::getNullValue(Bitwidth);
+ ComputeMaskedBits(Op1, DemandedMask, KnownZero1, KnownOne1);
+
+ if ((KnownZero0 | KnownOne1).isAllOnesValue())
+ return Op0;
+
+ if ((KnownZero1 | KnownOne0).isAllOnesValue())
+ return Op1;
+
// Try some generic simplifications for associative operations.
if (Value *V = SimplifyAssociativeBinOp(Instruction::And, Op0, Op1, Q,
MaxRecurse))
OpenPOWER on IntegriCloud