diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-02-27 01:44:11 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-02-27 01:44:11 +0000 |
| commit | f5c8a0b83f460ce1ac0390e4342f3a92ab748790 (patch) | |
| tree | b9255b71f4bb0b4940fa3f2168a087f06daa260e /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
| parent | 7422e470f3cf5c7248f248bfcbd09278ee171dee (diff) | |
| download | bcm5719-llvm-f5c8a0b83f460ce1ac0390e4342f3a92ab748790.tar.gz bcm5719-llvm-f5c8a0b83f460ce1ac0390e4342f3a92ab748790.zip | |
Fold (A^B) == A -> B == 0
and (A-B) == A -> B == 0
llvm-svn: 26394
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 99677cc5de6..38a84cd8a4c 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3876,6 +3876,32 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { if (Instruction *R = visitSetCondInstWithCastAndCast(I)) return R; } + + if (I.getOpcode() == Instruction::SetNE || + I.getOpcode() == Instruction::SetEQ) { + Value *A, *B; + if (match(Op0, m_Xor(m_Value(A), m_Value(B))) && + (A == Op1 || B == Op1)) { + // (A^B) == A -> B == 0 + Value *OtherVal = A == Op1 ? B : A; + return BinaryOperator::create(I.getOpcode(), OtherVal, + Constant::getNullValue(A->getType())); + } else if (match(Op1, m_Xor(m_Value(A), m_Value(B))) && + (A == Op0 || B == Op0)) { + // A == (A^B) -> B == 0 + Value *OtherVal = A == Op0 ? B : A; + return BinaryOperator::create(I.getOpcode(), OtherVal, + Constant::getNullValue(A->getType())); + } else if (match(Op0, m_Sub(m_Value(A), m_Value(B))) && A == Op1) { + // (A-B) == A -> B == 0 + return BinaryOperator::create(I.getOpcode(), B, + Constant::getNullValue(B->getType())); + } else if (match(Op1, m_Sub(m_Value(A), m_Value(B))) && A == Op0) { + // A == (A-B) -> B == 0 + return BinaryOperator::create(I.getOpcode(), B, + Constant::getNullValue(B->getType())); + } + } return Changed ? &I : 0; } |

