aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2012-03-27 17:44:52 +0000
committerChad Rosier <mcrosier@apple.com>2012-03-27 17:44:52 +0000
commitd23a64cc164529739adaedb397e6279269f78efb (patch)
treed86a97ed65b407a85a4b110330d364770de0be8d /lib/Analysis/InstructionSimplify.cpp
parent805543068eb7407d718b0359f54b342d7094d0ea (diff)
downloadexternal_llvm-d23a64cc164529739adaedb397e6279269f78efb.zip
external_llvm-d23a64cc164529739adaedb397e6279269f78efb.tar.gz
external_llvm-d23a64cc164529739adaedb397e6279269f78efb.tar.bz2
Reapply r153423; the original commit was fine. The failing test, distray, had
undefined behavior, which Rafael was kind enough to fix. Original commit message for r153423: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153521 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 16e7a72..28400b0 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/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))