[llvm] [SelectionDAG] Fold (avg x, 0) -> x >> 1 (PR #85581)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 08:55:53 PDT 2024


================
@@ -5083,7 +5083,18 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
   if (N0 == N1 && Level >= AfterLegalizeTypes)
     return N0;
 
-  // TODO If we use avg for scalars anywhere, we can add (avgfl x, 0) -> x >> 1
+  // Fold (avg x, 0) -> x >> 1
+  if (isNullOrNullSplat(N0))
----------------
jayfoad wrote:

Also if you are intentionally improving the handling of vectors with undefs then you should add tests for that.

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


More information about the llvm-commits mailing list