@@ -2643,23 +2643,16 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
2643
2643
// with binop identity constant. But creating a select with non-constant
2644
2644
// arm may not be reversible due to poison semantics. Is that a good
2645
2645
// canonicalization?
2646
- Value *A;
2647
- if (match (Op0, m_OneUse (m_SExt (m_Value (A)))) &&
2648
- A->getType ()->isIntOrIntVectorTy (1 ))
2649
- return SelectInst::Create (A, Op1, Constant::getNullValue (Ty));
2650
- if (match (Op1, m_OneUse (m_SExt (m_Value (A)))) &&
2646
+ Value *A, *B;
2647
+ if (match (&I, m_c_And (m_OneUse (m_SExt (m_Value (A))), m_Value (B))) &&
2651
2648
A->getType ()->isIntOrIntVectorTy (1 ))
2652
- return SelectInst::Create (A, Op0 , Constant::getNullValue (Ty));
2649
+ return SelectInst::Create (A, B , Constant::getNullValue (Ty));
2653
2650
2654
2651
// Similarly, a 'not' of the bool translates to a swap of the select arms:
2655
- // ~sext(A) & Op1 --> A ? 0 : Op1
2656
- // Op0 & ~sext(A) --> A ? 0 : Op0
2657
- if (match (Op0, m_Not (m_SExt (m_Value (A)))) &&
2652
+ // ~sext(A) & B / B & ~sext(A) --> A ? 0 : B
2653
+ if (match (&I, m_c_And (m_Not (m_SExt (m_Value (A))), m_Value (B))) &&
2658
2654
A->getType ()->isIntOrIntVectorTy (1 ))
2659
- return SelectInst::Create (A, Constant::getNullValue (Ty), Op1);
2660
- if (match (Op1, m_Not (m_SExt (m_Value (A)))) &&
2661
- A->getType ()->isIntOrIntVectorTy (1 ))
2662
- return SelectInst::Create (A, Constant::getNullValue (Ty), Op0);
2655
+ return SelectInst::Create (A, Constant::getNullValue (Ty), B);
2663
2656
2664
2657
// (iN X s>> (N-1)) & Y --> (X s< 0) ? Y : 0 -- with optional sext
2665
2658
if (match (&I, m_c_And (m_OneUse (m_SExtOrSelf (
@@ -3603,12 +3596,9 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
3603
3596
// with binop identity constant. But creating a select with non-constant
3604
3597
// arm may not be reversible due to poison semantics. Is that a good
3605
3598
// canonicalization?
3606
- if (match (Op0, m_OneUse (m_SExt (m_Value (A)))) &&
3607
- A->getType ()->isIntOrIntVectorTy (1 ))
3608
- return SelectInst::Create (A, ConstantInt::getAllOnesValue (Ty), Op1);
3609
- if (match (Op1, m_OneUse (m_SExt (m_Value (A)))) &&
3599
+ if (match (&I, m_c_Or (m_OneUse (m_SExt (m_Value (A))), m_Value (B))) &&
3610
3600
A->getType ()->isIntOrIntVectorTy (1 ))
3611
- return SelectInst::Create (A, ConstantInt::getAllOnesValue (Ty), Op0 );
3601
+ return SelectInst::Create (A, ConstantInt::getAllOnesValue (Ty), B );
3612
3602
3613
3603
// Note: If we've gotten to the point of visiting the outer OR, then the
3614
3604
// inner one couldn't be simplified. If it was a constant, then it won't
0 commit comments