[PATCH] D156437: [RISCV] Reverse CFI offset order for callee-saved registers stored by Zcmp push for correct stack unwinding.

Jim Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 07:36:30 PDT 2023


Jim created this revision.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
Jim requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.

Issue mentioned: https://github.com/riscv/riscv-code-size-reduction/issues/182

The order of callee-saved registers stored by Zcmp push in memory is reversed.

Pseudo code for cm.push in https://github.com/riscv/riscv-code-size-reduction/releases/download/v1.0.4-1/Zc.1.0.4-1.pdf

  if (XLEN==32) bytes=4; else bytes=8;
  
  addr=sp-bytes;
  for(i in 27,26,25,24,23,22,21,20,19,18,9,8,1)  {
    //if register i is in xreg_list
    if (xreg_list[i]) {
      switch(bytes) {
        4:  asm("sw x[i], 0(addr)");
        8:  asm("sd x[i], 0(addr)");
      }
      addr-=bytes;
    }
  }

The placement order for push is s11, s10, ..., ra.

CFI offset should be calculed as reversed order for correct stack unwinding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156437

Files:
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/test/CodeGen/RISCV/push-pop-popret.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156437.544771.patch
Type: text/x-patch
Size: 10937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/50ec35fb/attachment.bin>


More information about the llvm-commits mailing list