[llvm] [DAG] Fold mismatched widened avg idioms to narrow form (#147946) (PR #163366)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 03:22:29 PDT 2025
================
@@ -16482,10 +16482,30 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
DAG, DL);
}
break;
- case ISD::AVGFLOORS:
- case ISD::AVGFLOORU:
case ISD::AVGCEILS:
case ISD::AVGCEILU:
+ // trunc (avgceilu (sext (x), sext (y))) -> avgceils(x, y)
+ // trunc (avgceils (zext (x), zext (y))) -> avgceilu(x, y)
+ if (N0.hasOneUse()) {
+ SDValue Op0 = N0.getOperand(0);
+ SDValue Op1 = N0.getOperand(1);
+ if (N0.getOpcode() == ISD::AVGCEILU) {
+ if (TLI.isOperationLegalOrCustom(ISD::AVGCEILS, VT) &&
----------------
RKSimon wrote:
I'd just keep to SEXT/ZEXT nodes for now - ideally we'd use value tracking along with a better implementation of `isTruncateFree(SDValue, EVT)` - but that's future work
https://github.com/llvm/llvm-project/pull/163366
More information about the llvm-commits
mailing list