[llvm] [SDAG] Shrink (abd? (?ext x) (?ext y)) (PR #171865)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 03:31:38 PST 2025
================
@@ -5787,6 +5787,23 @@ SDValue DAGCombiner::visitABD(SDNode *N) {
DAG.SignBitIsZero(N0) && DAG.SignBitIsZero(N1))
return DAG.getNode(ISD::ABDU, DL, VT, N1, N0);
+ // fold (abds (?ext x), (?ext y)) -> (zext (abd? x, y))
+ if (sd_match(N,
+ m_c_BinOp(ISD::ABDU, m_ZExt(m_Value(X)), m_ZExt(m_Value(Y)))) ||
+ sd_match(N,
+ m_c_BinOp(ISD::ABDS, m_SExt(m_Value(X)), m_SExt(m_Value(Y))))) {
+ EVT SmallVT = X.getScalarValueSizeInBits() > Y.getScalarValueSizeInBits()
+ ? X.getValueType()
+ : Y.getValueType();
+ auto ExtedX = DAG.getExtOrTrunc(N0->getOpcode(), X, X, SmallVT);
+ auto ExtedY = DAG.getExtOrTrunc(N0->getOpcode(), Y, Y, SmallVT);
----------------
RKSimon wrote:
Check the getExtOrTrunc syntax, I think you need something like:
```
SDValue ExtedX = DAG.getExtOrTrunc(X, DL, SmallVT, N->getOperand(0)->getOpcode());
SDValue ExtedY = DAG.getExtOrTrunc(Y, DL, SmallVT, N->getOperand(0)->getOpcode());
```
Also, put this inside the LegalOperations check to avoid creating nodes that never get used.
https://github.com/llvm/llvm-project/pull/171865
More information about the llvm-commits
mailing list