[PATCH] D82660: [RISCV] Optimize multiplication by specific immediates

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 08:10:31 PDT 2020


benshi001 created this revision.
benshi001 added reviewers: asb, lenary, luismarques, shiva0217.
Herald added subscribers: llvm-commits, evandro, apazos, sameer.abuasal, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
Herald added a project: LLVM.
benshi001 added a reviewer: kito-cheng.
benshi001 added a comment.

This patch can not cover all cases (especially "call __mulsi3" on rv32 without M extension), but at least it works well for most cases.

Maybe a better solution is make ISD::MUL as Custom, which I will try later. You are appreciated to review and accept such a partial optimization.


(mul r, imm) -> (add (shl r, log2(imm-1)), r) // if imm==power(2,N)+1
(mul r, imm) -> (sub (shl r, log2(imm+1)), r) // if imm==power(2,N)-1


https://reviews.llvm.org/D82660

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/test/CodeGen/RISCV/mul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82660.273727.patch
Type: text/x-patch
Size: 5236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200626/10601fa0/attachment.bin>


More information about the llvm-commits mailing list