Skip to content

Commit

Permalink
[DAG] visitAND - refactor "and (sub 0, ext(bool X)), 1 --> zext(bool …
Browse files Browse the repository at this point in the history
…X)" to use SDPatternMatch.
  • Loading branch information
RKSimon committed Nov 5, 2024
1 parent 119aac0 commit 5df3872
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7399,16 +7399,13 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
//
// Note: the SimplifyDemandedBits fold below can make an information-losing
// transform, and then we have no way to find this better fold.
if (N1C && N1C->isOne() && N0.getOpcode() == ISD::SUB) {
if (isNullOrNullSplat(N0.getOperand(0))) {
SDValue SubRHS = N0.getOperand(1);
if (SubRHS.getOpcode() == ISD::ZERO_EXTEND &&
SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
return SubRHS;
if (SubRHS.getOpcode() == ISD::SIGN_EXTEND &&
SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, SubRHS.getOperand(0));
}
if (sd_match(N, m_And(m_Sub(m_Zero(), m_Value(X)), m_One()))) {
if (X.getOpcode() == ISD::ZERO_EXTEND &&
X.getOperand(0).getScalarValueSizeInBits() == 1)
return X;
if (X.getOpcode() == ISD::SIGN_EXTEND &&
X.getOperand(0).getScalarValueSizeInBits() == 1)
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, X.getOperand(0));
}

// fold (and (sign_extend_inreg x, i16 to i32), 1) -> (and x, 1)
Expand Down

0 comments on commit 5df3872

Please sign in to comment.