[llvm] [DAG] Add legalization handling for AVGCEIL/AVGFLOOR nodes (PR #92096)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 01:38:23 PDT 2024
================
@@ -5241,6 +5241,21 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
return DAG.getNode(ISD::SRL, DL, VT, X,
DAG.getShiftAmountConstant(1, VT, DL));
+ // Fold avgflooru(x,y) -> avgceilu(x,y-1) iff y != 0
+ // Fold avgflooru(x,y) -> avgceilu(x-1,y) iff x != 0
+ // Check if avgflooru isn't legal/custom but avgceilu is.
+ if (Opcode == ISD::AVGFLOORU && !hasOperation(ISD::AVGFLOORU, VT) &&
+ (!LegalOperations || hasOperation(ISD::AVGCEILU, VT))) {
+ if (DAG.isKnownNeverZero(N0))
----------------
jayfoad wrote:
Maybe handle N1 before N0? I assume if either one is a constant it will have been canonicalized to the RHS, and you should prefer to subtract 1 from a constant.
https://github.com/llvm/llvm-project/pull/92096
More information about the llvm-commits
mailing list