On 6/7/2026 10:11 PM, Monk Chiang wrote:
The trampoline code generation for Zicfilp (CFI landing pads) uses
three registers and includes a redundant LUI instruction.

Before this patch, the trampoline code was:

   lpad    0
   auipc   t3, 0
   l[wd]   t0, (target_function_offset - 4)(t3)
   l[wd]   t3, (static_chain_offset - 4)(t3)
   lui     t2, 0
   jr      t0

This uses three registers (t0, t2, t3) and has a redundant "lui t2, 0"
instruction that is never used.

After this patch, the trampoline code is:

   lpad    0
   auipc   t3, 0
   l[wd]   t2, (target_function_offset - 4)(t3)
   l[wd]   t3, (static_chain_offset - 4)(t3)
   jr      t2
   nop

The optimization removes the redundant LUI instruction, uses only two
registers (t2, t3), and adds a nop for proper 8-byte alignment to avoid
-Wpadded warnings.

Changes in v2:
- Fix zicfilp-trampoline test for Linux targets.
- Fix line length exceeding 80 characters.

gcc/

        * config/riscv/riscv.cc (riscv_trampoline_init): Remove redundant
        LUI instruction.

gcc/testsuite/

        * gcc.target/riscv/zicfilp-trampoline.c: New test.
THanks.  I know you've got commit privs, but we've got the patchwork meeting in a couple hours and there's no sense in having this on the list of patches to review, so I went ahead and pushed it myself.

Thanks again!

jeff

Reply via email to