[PATCH] D115310: [RISCV] Use MULHU for more division by constant cases.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 7 17:22:06 PST 2021
craig.topper created this revision.
craig.topper added reviewers: jrtc27, asb, luismarques, frasercrmck.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, StephenFan, vkmr, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.
D113805 <https://reviews.llvm.org/D113805> improved handling of i32 divu/remu on RV64. The basic idea
from that can be extended to (mul (and X, C2), C1 <https://reviews.llvm.org/C1>) where C2 is any
mask constant.
We can replace the and with an SLLI by shifting by the number of
leading zeros in C2 if we also shift C1 <https://reviews.llvm.org/C1> left by XLen - lzcnt(C1 <https://reviews.llvm.org/C1>)
bits. This will give the full product XLen additional trailing zeros,
putting the result in the output of MULHU. If we can't use ANDI,
ZEXT.H, or ZEXT.W, this will avoid materializing C2 in a register.
The downside is it make take 1 additional instruction to create C1 <https://reviews.llvm.org/C1>.
But since that's not on the critical path, it can hopefully be
interleaved with other operations.
The previous tablegen pattern is replaced by custom isel code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115310
Files:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoM.td
llvm/test/CodeGen/RISCV/div.ll
llvm/test/CodeGen/RISCV/pr51206.ll
llvm/test/CodeGen/RISCV/urem-lkk.ll
llvm/test/CodeGen/RISCV/xaluo.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115310.392602.patch
Type: text/x-patch
Size: 7926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211208/2a132a3c/attachment-0001.bin>
More information about the llvm-commits
mailing list