aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-07-23 17:57:01 +0000
committerChris Lattner <sabre@nondot.org>2003-07-23 17:57:01 +0000
commitc6a8aff3f617f351ed16aaa37580b1284b52e57a (patch)
treedbd21d2651e08a2fe30fd086ee4d78f31187574f /lib/Transforms
parent2b8e478b5d31f5fb5bf9bb5b9cf8ebea6350ffce (diff)
downloadexternal_llvm-c6a8aff3f617f351ed16aaa37580b1284b52e57a.zip
external_llvm-c6a8aff3f617f351ed16aaa37580b1284b52e57a.tar.gz
external_llvm-c6a8aff3f617f351ed16aaa37580b1284b52e57a.tar.bz2
IC: (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
Minor code cleanup git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7262 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 4e36927..1ace95f 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -493,19 +493,31 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
return ReplaceInstUsesWith(I, Op1);
// and X, -1 == X
- if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1))
+ if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) {
if (RHS->isAllOnesValue())
return ReplaceInstUsesWith(I, Op0);
+ // (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
+ if (Instruction *Op0I = dyn_cast<Instruction>(Op0))
+ if (Op0I->getOpcode() == Instruction::Xor && isOnlyUse(Op0))
+ if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
+ std::string Op0Name = Op0I->getName(); Op0I->setName("");
+ Instruction *And = BinaryOperator::create(Instruction::And,
+ Op0I->getOperand(0), RHS,
+ Op0Name);
+ InsertNewInstBefore(And, I);
+ return BinaryOperator::create(Instruction::Xor, And, *RHS & *Op0CI);
+ }
+ }
+
Value *Op0NotVal = dyn_castNotVal(Op0);
Value *Op1NotVal = dyn_castNotVal(Op1);
// (~A & ~B) == (~(A | B)) - Demorgan's Law
if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) {
Instruction *Or = BinaryOperator::create(Instruction::Or, Op0NotVal,
- Op1NotVal,I.getName()+".demorgan",
- &I);
- WorkList.push_back(Or);
+ Op1NotVal,I.getName()+".demorgan");
+ InsertNewInstBefore(Or, I);
return BinaryOperator::createNot(Or);
}