[llvm] [DAG] foldShiftToAvg - recognize sub(x, xor(y, -1)) >> 1 as avgceil[su] (PR #182616)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 03:36:56 PDT 2026


================
@@ -12432,6 +12432,36 @@ static SDValue combineMinNumMaxNumImpl(const SDLoc &DL, EVT VT, SDValue LHS,
   }
 }
 
+// Check whether sub(X, xor Y, C) matches the all_ones xor form:
+//   C := all_ones (after truncation to elt width) -> (xor Y, C) == ~Y,
+//   thus, sub (X, xor Y, c) == (X - ~Y) == (X + Y + 1).
+// Returns AVGCEILS if sext(X) and sext(Y),
+//         AVGCEILU if zext(X) and zext(Y),
+//         0 otherwise.
+static unsigned getAvgCeilFromXor(SDValue XorRHS, SDValue X, SDValue Y) {
----------------
RKSimon wrote:

`std::optional<unsigned>` instead of "0 otherwise"

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


More information about the llvm-commits mailing list