[llvm] [DAG] expandAVG - attempt to extend to a wider integer type for the add/shift to avoid overflow handling (PR #95788)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 07:51:53 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.
+ if (VT.isScalarInteger()) {
+ unsigned BW = VT.getScalarSizeInBits();
+ EVT ExtVT = VT.getIntegerVT(*DAG.getContext(), 2 * BW);
+ if (isTypeLegal(ExtVT) &&
+ ((!IsSigned && isZExtFree(VT, ExtVT)) || isTruncateFree(ExtVT, VT))) {
----------------
jayfoad wrote:
I guess there is no `isSExtFree` that you can use? You just assume the sext is free if the truncate is free?
https://github.com/llvm/llvm-project/pull/95788
More information about the llvm-commits
mailing list