@@ -5253,24 +5253,25 @@ SDValue DAGCombiner::visitABD(SDNode *N) {
5253
5253
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
5254
5254
return DAG.getNode(Opcode, DL, N->getVTList(), N1, N0);
5255
5255
5256
- if (VT.isVector()) {
5256
+ if (VT.isVector())
5257
5257
if (SDValue FoldedVOp = SimplifyVBinOp(N, DL))
5258
5258
return FoldedVOp;
5259
5259
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
-
5270
5260
// fold (abd x, undef) -> 0
5271
5261
if (N0.isUndef() || N1.isUndef())
5272
5262
return DAG.getConstant(0, DL, VT);
5273
5263
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
+
5274
5275
// fold (abds x, y) -> (abdu x, y) iff both args are known positive
5275
5276
if (Opcode == ISD::ABDS && hasOperation(ISD::ABDU, VT) &&
5276
5277
DAG.SignBitIsZero(N0) && DAG.SignBitIsZero(N1))
0 commit comments