Skip to content

Commit f6c04d6

Browse files
RKSimonPhilippRados
authored andcommitted
[DAG] visitAND - refactor "and (sub 0, ext(bool X)), 1 --> zext(bool X)" to use SDPatternMatch.
1 parent c73953c commit f6c04d6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7399,16 +7399,13 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
73997399
//
74007400
// Note: the SimplifyDemandedBits fold below can make an information-losing
74017401
// transform, and then we have no way to find this better fold.
7402-
if (N1C && N1C->isOne() && N0.getOpcode() == ISD::SUB) {
7403-
if (isNullOrNullSplat(N0.getOperand(0))) {
7404-
SDValue SubRHS = N0.getOperand(1);
7405-
if (SubRHS.getOpcode() == ISD::ZERO_EXTEND &&
7406-
SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
7407-
return SubRHS;
7408-
if (SubRHS.getOpcode() == ISD::SIGN_EXTEND &&
7409-
SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
7410-
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, SubRHS.getOperand(0));
7411-
}
7402+
if (sd_match(N, m_And(m_Sub(m_Zero(), m_Value(X)), m_One()))) {
7403+
if (X.getOpcode() == ISD::ZERO_EXTEND &&
7404+
X.getOperand(0).getScalarValueSizeInBits() == 1)
7405+
return X;
7406+
if (X.getOpcode() == ISD::SIGN_EXTEND &&
7407+
X.getOperand(0).getScalarValueSizeInBits() == 1)
7408+
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, X.getOperand(0));
74127409
}
74137410

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

0 commit comments

Comments
 (0)