diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-16 04:26:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-16 04:26:55 +0000 |
commit | d09b5baee8d9b5dfe900bd156658fe64815becc8 (patch) | |
tree | c3619005132807e86f79b4116adf0dd5e08a6df5 /lib | |
parent | 383710a9552054c0050468674822ec69d7616bf3 (diff) | |
download | external_llvm-d09b5baee8d9b5dfe900bd156658fe64815becc8.zip external_llvm-d09b5baee8d9b5dfe900bd156658fe64815becc8.tar.gz external_llvm-d09b5baee8d9b5dfe900bd156658fe64815becc8.tar.bz2 |
simplify code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59390 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index c2df3a5..7e73727 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4210,30 +4210,25 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { /// we can simplify this expression to "cond ? C : D or B". static Instruction *MatchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D) { - // If A is not a select of constants, this can't match. + // If A is not a select of -1/0, this cannot match. Value *Cond = 0, *Cond2 = 0; - ConstantInt *C1, *C2; - if (!match(A, m_Select(m_Value(Cond), m_ConstantInt(C1), m_ConstantInt(C2)))) + if (!match(A, m_Select(m_Value(Cond), m_ConstantInt(-1), m_ConstantInt(0)))) return 0; #define SELECT_MATCH(Val, I1, I2) \ m_Select(m_Value(Val), m_ConstantInt(I1), m_ConstantInt(I2)) - // Handle "cond ? -1 : 0". - if (C1->isAllOnesValue() && C2->isZero()) { - // ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B. - if (match(D, SELECT_MATCH(Cond2, 0, -1)) && Cond2 == Cond) - return SelectInst::Create(Cond, C, B); - if (match(D, m_Not(SELECT_MATCH(Cond2, -1, 0))) && Cond2 == Cond) - return SelectInst::Create(Cond, C, B); - // ((cond?-1:0)&C) | ((cond?0:-1)&D) -> cond ? C : D. - if (match(B, SELECT_MATCH(Cond2, 0, -1)) && Cond2 == Cond) - return SelectInst::Create(Cond, C, D); - if (match(B, m_Not(SELECT_MATCH(Cond2, -1, 0))) && Cond2 == Cond) - return SelectInst::Create(Cond, C, D); - } + // ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B. + if (match(D, SELECT_MATCH(Cond2, 0, -1)) && Cond2 == Cond) + return SelectInst::Create(Cond, C, B); + if (match(D, m_Not(SELECT_MATCH(Cond2, -1, 0))) && Cond2 == Cond) + return SelectInst::Create(Cond, C, B); + // ((cond?-1:0)&C) | ((cond?0:-1)&D) -> cond ? C : D. + if (match(B, SELECT_MATCH(Cond2, 0, -1)) && Cond2 == Cond) + return SelectInst::Create(Cond, C, D); + if (match(B, m_Not(SELECT_MATCH(Cond2, -1, 0))) && Cond2 == Cond) + return SelectInst::Create(Cond, C, D); #undef SELECT_MATCH - return 0; } |