Skip to content

Commit 7273ad1

Browse files
committed
[DAG] visitABD - rewrite "(abs x, 0)" folds to use SDPatternMatch
No need for this to be vector specific, and its more likely that scalar cases will appear after #92576
1 parent 9f5c8de commit 7273ad1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5253,24 +5253,25 @@ SDValue DAGCombiner::visitABD(SDNode *N) {
52535253
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
52545254
return DAG.getNode(Opcode, DL, N->getVTList(), N1, N0);
52555255

5256-
if (VT.isVector()) {
5256+
if (VT.isVector())
52575257
if (SDValue FoldedVOp = SimplifyVBinOp(N, DL))
52585258
return FoldedVOp;
52595259

5260-
// fold (abds x, 0) -> abs x
5261-
// fold (abdu x, 0) -> x
5262-
if (ISD::isConstantSplatVectorAllZeros(N1.getNode())) {
5263-
if (Opcode == ISD::ABDS)
5264-
return DAG.getNode(ISD::ABS, DL, VT, N0);
5265-
if (Opcode == ISD::ABDU)
5266-
return N0;
5267-
}
5268-
}
5269-
52705260
// fold (abd x, undef) -> 0
52715261
if (N0.isUndef() || N1.isUndef())
52725262
return DAG.getConstant(0, DL, VT);
52735263

5264+
SDValue X;
5265+
5266+
// fold (abds x, 0) -> abs x
5267+
if (sd_match(N, m_c_BinOp(ISD::ABDS, m_Value(X), m_Zero())) &&
5268+
(!LegalOperations || hasOperation(ISD::ABS, VT)))
5269+
return DAG.getNode(ISD::ABS, DL, VT, X);
5270+
5271+
// fold (abdu x, 0) -> x
5272+
if (sd_match(N, m_c_BinOp(ISD::ABDU, m_Value(X), m_Zero())))
5273+
return X;
5274+
52745275
// fold (abds x, y) -> (abdu x, y) iff both args are known positive
52755276
if (Opcode == ISD::ABDS && hasOperation(ISD::ABDU, VT) &&
52765277
DAG.SignBitIsZero(N0) && DAG.SignBitIsZero(N1))

0 commit comments

Comments
 (0)