diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-12 19:17:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-12 19:17:27 +0000 |
commit | e132d95b628af3dd1ef855033b0ce0651a0e460f (patch) | |
tree | 10497cf249fa724c3d596332b5b13e79fdd0f83f /lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | 67ca7689278d14c732db49bbd11869806148f266 (diff) |
Simplify code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index bfc51db1b7..15b0bbcdfc 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -241,7 +241,8 @@ static inline Value *dyn_castFoldableMul(Value *V) { // dyn_castMaskingAnd - If this value is an And instruction masking a value with // a constant, return the constant being anded with. // -static inline Constant *dyn_castMaskingAnd(Value *V) { +template<class ValueType> +static inline Constant *dyn_castMaskingAnd(ValueType *V) { if (Instruction *I = dyn_cast<Instruction>(V)) if (I->getOpcode() == Instruction::And) return dyn_cast<Constant>(I->getOperand(1)); @@ -613,16 +614,12 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { } // (A & C1)|(A & C2) == A & (C1|C2) - if (BinaryOperator *BO0 = dyn_cast<BinaryOperator>(Op0)) - if (BinaryOperator *BO1 = dyn_cast<BinaryOperator>(Op1)) - if (BO0->getOperand(0) == BO1->getOperand(0) && - BO0->getOpcode() == Instruction::And && - BO1->getOpcode() == Instruction::And) - if (ConstantIntegral *C0 = - dyn_cast<ConstantIntegral>(BO0->getOperand(1))) - if (ConstantIntegral *C1 = - dyn_cast<ConstantIntegral>(BO1->getOperand(1))) - return BinaryOperator::create(Instruction::And, BO0->getOperand(0), + if (Instruction *LHS = dyn_cast<BinaryOperator>(Op0)) + if (Instruction *RHS = dyn_cast<BinaryOperator>(Op1)) + if (LHS->getOperand(0) == RHS->getOperand(0)) + if (Constant *C0 = dyn_castMaskingAnd(LHS)) + if (Constant *C1 = dyn_castMaskingAnd(RHS)) + return BinaryOperator::create(Instruction::And, LHS->getOperand(0), *C0 | *C1); Value *Op0NotVal = dyn_castNotVal(Op0); |