Skip to content

Commit 780b046

Browse files
committed
[InstCombine] Use m_c_And/m_c_Or instead of duplicate logic. NFC.
See also https://reviews.llvm.org/D153148#inline-1535588
1 parent 7560356 commit 780b046

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,23 +2643,16 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
26432643
// with binop identity constant. But creating a select with non-constant
26442644
// arm may not be reversible due to poison semantics. Is that a good
26452645
// 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))) &&
26512648
A->getType()->isIntOrIntVectorTy(1))
2652-
return SelectInst::Create(A, Op0, Constant::getNullValue(Ty));
2649+
return SelectInst::Create(A, B, Constant::getNullValue(Ty));
26532650

26542651
// 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))) &&
26582654
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);
26632656

26642657
// (iN X s>> (N-1)) & Y --> (X s< 0) ? Y : 0 -- with optional sext
26652658
if (match(&I, m_c_And(m_OneUse(m_SExtOrSelf(
@@ -3603,12 +3596,9 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
36033596
// with binop identity constant. But creating a select with non-constant
36043597
// arm may not be reversible due to poison semantics. Is that a good
36053598
// 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))) &&
36103600
A->getType()->isIntOrIntVectorTy(1))
3611-
return SelectInst::Create(A, ConstantInt::getAllOnesValue(Ty), Op0);
3601+
return SelectInst::Create(A, ConstantInt::getAllOnesValue(Ty), B);
36123602

36133603
// Note: If we've gotten to the point of visiting the outer OR, then the
36143604
// inner one couldn't be simplified. If it was a constant, then it won't

0 commit comments

Comments
 (0)