Skip to content

Commit cdb6ba5

Browse files
committed
[RISCV][NFC] Match 3/5/9 * 3/5/9 * 2^N without a loop
1 parent bd06efb commit cdb6ba5

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16634,23 +16634,12 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
1663416634
}
1663516635
}
1663616636

16637-
for (uint64_t Divisor : {3, 5, 9}) {
16638-
if (MulAmt % Divisor != 0)
16639-
continue;
16640-
uint64_t MulAmt2 = MulAmt / Divisor;
16641-
// 3/5/9 * 3/5/9 * 2^N - In particular, this covers multiples
16642-
// of 25 which happen to be quite common.
16643-
if (int ShBAmount = isShifted359(MulAmt2, Shift)) {
16644-
SDLoc DL(N);
16645-
SDValue Mul359A =
16646-
DAG.getNode(RISCVISD::SHL_ADD, DL, VT, X,
16647-
DAG.getConstant(Log2_64(Divisor - 1), DL, VT), X);
16648-
SDValue Mul359B =
16649-
DAG.getNode(RISCVISD::SHL_ADD, DL, VT, Mul359A,
16650-
DAG.getConstant(ShBAmount, DL, VT), Mul359A);
16651-
return DAG.getNode(ISD::SHL, DL, VT, Mul359B,
16652-
DAG.getConstant(Shift, DL, VT));
16653-
}
16637+
// 3/5/9 * 3/5/9 * 2^N - In particular, this covers multiples
16638+
// of 25 which happen to be quite common.
16639+
Shift = llvm::countr_zero(MulAmt);
16640+
if (SDValue V = expandMulToShlAddShlAdd(N, DAG, MulAmt >> Shift)) {
16641+
SDLoc DL(N);
16642+
return DAG.getNode(ISD::SHL, DL, VT, V, DAG.getConstant(Shift, DL, VT));
1665416643
}
1665516644
}
1665616645

0 commit comments

Comments
 (0)