[PATCH] D105769: [RISCV] Use DIVUW/REMUW/DIVW instructions for i8/i16/i32 udiv/urem/sdiv when LHS is constant.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 10 18:26:11 PDT 2021


craig.topper created this revision.
craig.topper added reviewers: asb, luismarques, jrtc27, frasercrmck, evandro, HsiangKai, arcbbb, khchen.
Herald added subscribers: StephenFan, vkmr, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, 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.

We don't really have optimizations for division with a constant
LHS. If we don't use a W instruction we end up needing to sign
or zero extend the RHS to use the 64-bit instruction.

I had to sign_extend i32 constants on the LHS instead of using
any_extend which becomes zero_extend. If we don't do this, constants
that were originally negative become harder to materialize. I think
this problem exists for more of our W instruction cases. For example
(i32 (shl -1, X)), but we don't have lit tests. I'll work on that
as a follow up.

I also left a FIXME for enabling W instruction for RHS constants
under -Oz.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105769

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/test/CodeGen/RISCV/div.ll
  llvm/test/CodeGen/RISCV/rem.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105769.357774.patch
Type: text/x-patch
Size: 6144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210711/abf09f5a/attachment.bin>


More information about the llvm-commits mailing list