[llvm] [DAG] expandAVG - attempt to extend to a wider integer type for the add/shift to avoid overflow handling (PR #95788)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 05:01:50 PDT 2024
================
@@ -9262,12 +9265,28 @@ SDValue TargetLowering::expandAVG(SDNode *N, SelectionDAG &DAG) const {
DAG.getShiftAmountConstant(1, VT, dl));
}
+ // For scalars, see if we can efficiently extend/truncate to use add+shift.
+ // We can always use SRL as we will be truncating away the extended sign bits.
+ if (VT.isScalarInteger()) {
+ unsigned BW = VT.getScalarSizeInBits();
+ EVT ExtVT = VT.getIntegerVT(*DAG.getContext(), 2 * BW);
+ if (isTypeLegal(ExtVT) && isTruncateFree(ExtVT, VT)) {
+ LHS = DAG.getNode(ExtOpc, dl, ExtVT, LHS);
+ RHS = DAG.getNode(ExtOpc, dl, ExtVT, RHS);
+ SDValue Avg = DAG.getNode(ISD::ADD, dl, ExtVT, LHS, RHS);
+ if (!IsFloor)
+ Avg = DAG.getNode(ISD::ADD, dl, ExtVT, Avg,
+ DAG.getConstant(1, dl, ExtVT));
----------------
RKSimon wrote:
Raise that as an Issue? I don't really want this PR to get pulled into future work like that.
https://github.com/llvm/llvm-project/pull/95788
More information about the llvm-commits
mailing list