[llvm] [DAGCombiner] Add combine avg from shifts (PR #113909)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 03:42:45 PDT 2024


================
@@ -11393,6 +11422,53 @@ static SDValue combineMinNumMaxNumImpl(const SDLoc &DL, EVT VT, SDValue LHS,
   }
 }
 
+SDValue DAGCombiner::foldShiftToAvg(SDNode *N) {
+  const unsigned Opcode = N->getOpcode();
+
+  // Convert (sr[al] (add n[su]w x, y)) -> (avgfloor[su] x, y)
+  if (Opcode != ISD::SRA && Opcode != ISD::SRL)
----------------
RKSimon wrote:

The sd_match() below should catch it - it'd be nice to ensure we have negative test coverage for this though

https://github.com/llvm/llvm-project/pull/113909


More information about the llvm-commits mailing list