[RISCV] Fold ADDIs into load/stores with nonzero offsets
authorLuís Marques <luismarques@lowrisc.org>
Wed, 24 Jun 2020 12:53:27 +0000 (13:53 +0100)
committerLuís Marques <luismarques@lowrisc.org>
Mon, 6 Jul 2020 16:32:57 +0000 (17:32 +0100)
commit61c2a0bb823677ce0e604b92e5dae65d9bd32b6e
tree35d9bea179a5ddcfa1a019fe2704af5bc1bd9f5b
parent52af9c59e3bb9068c5cdecf2a79caf4c16d3b347
[RISCV] Fold ADDIs into load/stores with nonzero offsets

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.

Differential Revision: https://reviews.llvm.org/D79690
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/test/CodeGen/RISCV/callee-saved-fpr32s.ll
llvm/test/CodeGen/RISCV/callee-saved-fpr64s.ll
llvm/test/CodeGen/RISCV/callee-saved-gprs.ll
llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll
llvm/test/CodeGen/RISCV/fp128.ll
llvm/test/CodeGen/RISCV/interrupt-attr-nocall.ll
llvm/test/CodeGen/RISCV/wide-mem.ll