diff options
author | Chris Lattner <sabre@nondot.org> | 2003-07-23 18:29:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-07-23 18:29:44 +0000 |
commit | ad44ebfff027899f45a645586a9a8bd3cb317eb5 (patch) | |
tree | 63fb746a491b475171cd7f871179cffb0f177477 /lib/Transforms | |
parent | 31a7f85346d4a379ea4dfad068df6193e3300e30 (diff) |
IC: (X & C1) | C2 --> (X | C2) & (C1|C2)
IC: (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
We are now guaranteed that all 'or's will be inside of 'and's, and all 'and's
will be inside of 'xor's, if the second operands are constants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 1ace95f28b..df0b3566be 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -538,10 +538,35 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { return ReplaceInstUsesWith(I, Op0); // or X, -1 == -1 - if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) + if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) { if (RHS->isAllOnesValue()) return ReplaceInstUsesWith(I, Op1); + if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) { + // (X & C1) | C2 --> (X | C2) & (C1|C2) + if (Op0I->getOpcode() == Instruction::And && isOnlyUse(Op0)) + if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) { + std::string Op0Name = Op0I->getName(); Op0I->setName(""); + Instruction *Or = BinaryOperator::create(Instruction::Or, + Op0I->getOperand(0), RHS, + Op0Name); + InsertNewInstBefore(Or, I); + return BinaryOperator::create(Instruction::And, Or, *RHS | *Op0CI); + } + + // (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2) + if (Op0I->getOpcode() == Instruction::Xor && isOnlyUse(Op0)) + if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) { + std::string Op0Name = Op0I->getName(); Op0I->setName(""); + Instruction *Or = BinaryOperator::create(Instruction::Or, + Op0I->getOperand(0), RHS, + Op0Name); + InsertNewInstBefore(Or, I); + return BinaryOperator::create(Instruction::Xor, Or, *Op0CI & *~*RHS); + } + } + } + Value *Op0NotVal = dyn_castNotVal(Op0); Value *Op1NotVal = dyn_castNotVal(Op1); |