diff options
| author | Bill Wendling <isanbard@gmail.com> | 2008-12-02 05:06:43 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2008-12-02 05:06:43 +0000 |
| commit | 21716dff5e2277719ce72b3db5d1a5e095e78321 (patch) | |
| tree | 449141d576bc7710a27452ae4ff1f99f54700fe1 /llvm/lib | |
| parent | ead1a61b47f364c5bf775c3d8fb226ce9d3163f1 (diff) | |
| download | bcm5719-llvm-21716dff5e2277719ce72b3db5d1a5e095e78321.tar.gz bcm5719-llvm-21716dff5e2277719ce72b3db5d1a5e095e78321.zip | |
- Reduce nesting.
- No need to do a swap on a canonicalized pattern.
No functionality change.
llvm-svn: 60397
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 8d7616053b1..109e76a47a3 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4447,30 +4447,24 @@ Instruction *InstCombiner::FoldOrOfICmps(Instruction &I, /// of the two constants is "all ones".) Instruction *InstCombiner::FoldOrWithConstants(BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C) { - if (ConstantInt *CI1 = dyn_cast<ConstantInt>(C)) { - Value *V1 = 0, *C2 = 0; - if (match(Op, m_And(m_Value(V1), m_Value(C2)))) { - ConstantInt *CI2 = dyn_cast<ConstantInt>(C2); - - if (!CI2) { - std::swap(V1, C2); - CI2 = dyn_cast<ConstantInt>(C2); - } - - if (CI2) { - APInt Xor = CI1->getValue() ^ CI2->getValue(); - if (Xor.isAllOnesValue()) { - if (V1 == B) { - Instruction *NewOp = - InsertNewInstBefore(BinaryOperator::CreateAnd(A, CI1), I); - return BinaryOperator::CreateOr(NewOp, B); - } - if (V1 == A) { - Instruction *NewOp = - InsertNewInstBefore(BinaryOperator::CreateAnd(B, CI1), I); - return BinaryOperator::CreateOr(NewOp, A); - } - } + ConstantInt *CI1 = dyn_cast<ConstantInt>(C); + if (!CI1) return 0; + + Value *V1 = 0, *C2 = 0; + if (match(Op, m_And(m_Value(V1), m_Value(C2)))) { + ConstantInt *CI2 = dyn_cast<ConstantInt>(C2); + if (!CI2) return 0; + + APInt Xor = CI1->getValue() ^ CI2->getValue(); + if (Xor.isAllOnesValue()) { + if (V1 == B) { + Instruction *NewOp = + InsertNewInstBefore(BinaryOperator::CreateAnd(A, CI1), I); + return BinaryOperator::CreateOr(NewOp, B); + } else if (V1 == A) { + Instruction *NewOp = + InsertNewInstBefore(BinaryOperator::CreateAnd(B, CI1), I); + return BinaryOperator::CreateOr(NewOp, A); } } } |

