[llvm] [AArch64] Improve the codegen for sdiv 2 (PR #98324)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 11:00:08 PDT 2024
================
@@ -6182,18 +6182,31 @@ SDValue TargetLowering::buildSDIVPow2WithCMov(
SDLoc DL(N);
SDValue N0 = N->getOperand(0);
SDValue Zero = DAG.getConstant(0, DL, VT);
- APInt Lg2Mask = APInt::getLowBitsSet(VT.getSizeInBits(), Lg2);
- SDValue Pow2MinusOne = DAG.getConstant(Lg2Mask, DL, VT);
+ SDValue CMov;
- // If N0 is negative, we need to add (Pow2 - 1) to it before shifting right.
- EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
- SDValue Cmp = DAG.getSetCC(DL, CCVT, N0, Zero, ISD::SETLT);
- SDValue Add = DAG.getNode(ISD::ADD, DL, VT, N0, Pow2MinusOne);
- SDValue CMov = DAG.getNode(ISD::SELECT, DL, VT, Cmp, Add, N0);
+ if (Lg2 == 1) {
+ // If Divisor is 2, add 1 << (BitWidth -1) to it before shifting right.
----------------
topperc wrote:
This comment isn't accurate. It's adding (N0 >> (BitWidth - 1)).
https://github.com/llvm/llvm-project/pull/98324
More information about the llvm-commits
mailing list