[PATCH] D157373: [RISCV] add a compress optimization for stack inst.

lcvon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 01:51:39 PDT 2023


lcvon007 added a comment.

In D157373#4594385 <https://reviews.llvm.org/D157373#4594385>, @craig.topper wrote:

> I think 2048 * 2 + 512 is not 3 addis with the new code. After adding 512, we can't do the remaining 4096 in two addis. We can only do a maximum of 4094 with 2 addis.

yes, I did not  consider the positive offset is only 2047,  I think we can list the condition like the following(Use 512 of RVCompressLen as example):
the instuctions include prologue and epilogue together.

1. [2048,  2047+512]: before opt: (addi + addi) x 2 , after opt: (addi + addi) x2: good
2. 2048 + 512: before opt: (addi + addi) x 2, after opt:  (addi + addi)  + addi + addi + addi : not good
3. (2048 + 512, 2048  - StackAlign + 2047] : before opt: (addi + addi) x 2, after opt:  (addi + addi + addi) x 2 : not good
4. 2048  -StackAlign + 2048 : before opt: (addi + addi) + (addi + addi + addi), after opt: (addi + addi + addi) x2: not good
5. (2048  -stackAlign + 2048, 2047 * 2 + 512] before opt: (addi + addi + addi) x 2, after opt : (addi + addi + addi) x 2: good
6. (2047 * 2 + 512, 2048 * 2 + 512]: before opt: (addi + addi + addi) x 2, after opt: (addi + addi + addi) + (addi + LUI + addi + add) not good
7. (2048 * 2 + 512, 2048  -StackAlign + 2047 * 2] : before opt: (addi + addi + addi) x 2, after opt:  (addi + lui + addi + add) x 2: not good
8. 2048 -StackAlign + 2048 + 2047: before opt: (addi + addi + addi) + addi + lui + addi + add, after opt:  (addi + lui + addi + add) x 2: not good
9. 2048 - StackAlign + 2048 + 2048: before opt: (addi + addi + addi) + addi + lui + addi + add, after opt: (addi + lui + addi + add) x 2: not good

10:  (2048 * 3 -StackAlign, +inf): before: (addi + lui+ addi + addi +add) * 2, after opt: (addi + lui+ addi + add) x 2
so the new conditions need to be:
if (StackSize <= 2047+ RVCompressLen || (StackSize > 2048 * 2- StackAlign && StackSize <= 2047 * 2 + RVCompressLen) || StackSize > 2048 * 3 -StackAlign), and I have adjusted it,   please help review(thanks very much).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157373/new/

https://reviews.llvm.org/D157373



More information about the llvm-commits mailing list