[PATCH] D79690: [RISCV] Fold ADDIs into load/stores with nonzero offsets

Luís Marques via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 10 11:42:20 PDT 2020


luismarques created this revision.
luismarques added reviewers: asb, lenary.
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, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
Herald added a project: LLVM.
luismarques added a parent revision: D79689: [RISCV] Add tests for folds of ADDIs into load/stores.

We can often fold an ADDI into the offset of load/store instructions:

  (load (addi base, off1), off2) -> (load base, off1+off2)
  (store val, (addi base, off1), off2) -> (store val, base, off1+off2)

This is possible when the off1+off2 continues to fit the 12-bit immediate. We remove the previous restriction where we would never fold the ADDIs if the load/stores had nonzero offsets. We now do the fold the the resulting constant still fits a 12-bit immediate, or if off1 is a variable's address and we know based on that variable's alignment that off1+offs2 won't overflow. The first case doesn't seem to currently be exercised by the backend, but the code change is simple and easy to reason about, and handling it specially was actually making the code and the surrounding comments harder to understand.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79690

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79690.263077.patch
Type: text/x-patch
Size: 4768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200510/7d0fb80b/attachment.bin>


More information about the llvm-commits mailing list