[llvm] [DAG] foldShiftToAvg - recognize sub(x, xor(y, -1)) >> 1 as avgceil[su] (PR #182616)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 02:23:43 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) {
+ auto *Splat = dyn_cast<ConstantSDNode>(XorRHS.getOperand(0));
+ if (!Splat)
+ return 0;
+
+ unsigned EltBits =
+ XorRHS.getValueType().getVectorElementType().getSizeInBits();
+ if (!Splat->getAPIntValue().trunc(EltBits).isAllOnes())
+ return 0;
----------------
arsenm wrote:
isAllOnesConstant?
https://github.com/llvm/llvm-project/pull/182616
More information about the llvm-commits
mailing list