mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 16:41:43 +00:00
[InstCombine] Use m_c_And/m_c_Or instead of duplicate logic. NFC.
See also https://reviews.llvm.org/D153148#inline-1535588
This commit is contained in:
parent
7560356a83
commit
780b046bd0
@ -2643,23 +2643,16 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
|
||||
// with binop identity constant. But creating a select with non-constant
|
||||
// arm may not be reversible due to poison semantics. Is that a good
|
||||
// canonicalization?
|
||||
Value *A;
|
||||
if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
Value *A, *B;
|
||||
if (match(&I, m_c_And(m_OneUse(m_SExt(m_Value(A))), m_Value(B))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, Op1, Constant::getNullValue(Ty));
|
||||
if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, Op0, Constant::getNullValue(Ty));
|
||||
return SelectInst::Create(A, B, Constant::getNullValue(Ty));
|
||||
|
||||
// Similarly, a 'not' of the bool translates to a swap of the select arms:
|
||||
// ~sext(A) & Op1 --> A ? 0 : Op1
|
||||
// Op0 & ~sext(A) --> A ? 0 : Op0
|
||||
if (match(Op0, m_Not(m_SExt(m_Value(A)))) &&
|
||||
// ~sext(A) & B / B & ~sext(A) --> A ? 0 : B
|
||||
if (match(&I, m_c_And(m_Not(m_SExt(m_Value(A))), m_Value(B))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, Constant::getNullValue(Ty), Op1);
|
||||
if (match(Op1, m_Not(m_SExt(m_Value(A)))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, Constant::getNullValue(Ty), Op0);
|
||||
return SelectInst::Create(A, Constant::getNullValue(Ty), B);
|
||||
|
||||
// (iN X s>> (N-1)) & Y --> (X s< 0) ? Y : 0 -- with optional sext
|
||||
if (match(&I, m_c_And(m_OneUse(m_SExtOrSelf(
|
||||
@ -3603,12 +3596,9 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
|
||||
// with binop identity constant. But creating a select with non-constant
|
||||
// arm may not be reversible due to poison semantics. Is that a good
|
||||
// canonicalization?
|
||||
if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
if (match(&I, m_c_Or(m_OneUse(m_SExt(m_Value(A))), m_Value(B))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, ConstantInt::getAllOnesValue(Ty), Op1);
|
||||
if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, ConstantInt::getAllOnesValue(Ty), Op0);
|
||||
return SelectInst::Create(A, ConstantInt::getAllOnesValue(Ty), B);
|
||||
|
||||
// Note: If we've gotten to the point of visiting the outer OR, then the
|
||||
// inner one couldn't be simplified. If it was a constant, then it won't
|
||||
|
Loading…
x
Reference in New Issue
Block a user