aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-12-02 05:06:43 +0000
committerBill Wendling <isanbard@gmail.com>2008-12-02 05:06:43 +0000
commitdda74e07025aea4a70385e8fb9fa5e59d2341577 (patch)
tree0115c6784efe84e3684cd6c576e050a25fee720d /lib/Transforms/Scalar/InstructionCombining.cpp
parentf8828eb41b2f8f0356ff6889c9924eade654e39a (diff)
downloadexternal_llvm-dda74e07025aea4a70385e8fb9fa5e59d2341577.zip
external_llvm-dda74e07025aea4a70385e8fb9fa5e59d2341577.tar.gz
external_llvm-dda74e07025aea4a70385e8fb9fa5e59d2341577.tar.bz2
- Reduce nesting.
- No need to do a swap on a canonicalized pattern. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60397 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 8d76160..109e76a 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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);
}
}
}