public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [RISCV] Change the generation mode of `adjust_sp_rtx` from  gen_insn to gen_SET.
@ 2023-01-06  6:56 jinma
  0 siblings, 0 replies; only message in thread
From: jinma @ 2023-01-06  6:56 UTC (permalink / raw)
  To: gcc-patches

From 35c1f22d3c9a6910103cf9688c5c2bc3d5b75c68 Mon Sep 17 00:00:00 2001
From: Jin Ma <jinma@linux.alibaba.com>
Date: Fri, 6 Jan 2023 14:47:37 +0800
Subject: [PATCH] [RISCV] Change the generation mode of `adjust_sp_rtx` from gen_insn to gen_SET.

The gen_insn method is used to generate `adjust_sp_rtx` here, which has certain
potential risks:

When the architecture adds pre-processing to `define_insn "adddi3"`, such as
`define_expend "adddi3"`, the gen_expand will be automatically called here,
causing the patern to emit directly, which will cause insn to enter REG_NOTE
for `DWARF` instead of patern.

The following error REG_NOTE occurred:
error: invalid rtl sharing found in the insn:
(insn 19 3 20 2 (parallel [
        ...
        ])
    (expr_list:REG_CFA_ADJUST_CFA
        (insn 18 0 0 (set (reg/f:DI 2 sp)
            (plus:DI (reg/f:DI 2 sp)
                (const_int -16 [0xfffffffffffffff0]))) -1
        (nil))))

In fact, the correct one should be the following:
(insn 19 3 20 2 (parallel [
        ...
        ])
    (expr_list:REG_CFA_ADJUST_CFA
        (set (reg/f:DI 2 sp)
            (plus:DI (reg/f:DI 2 sp)
                (const_int -16 [0xfffffffffffffff0])))))

Following the treatment of arm or other architectures, it is more reasonable to
use gen_SET here.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_adjust_libcall_cfi_prologue):
        (riscv_adjust_libcall_cfi_epilogue):
---
 gcc/config/riscv/riscv.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 9a53999a39d..eab0500262f 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -5044,8 +5044,9 @@ riscv_adjust_libcall_cfi_prologue ()
       }

   /* Debug info for adjust sp.  */
-  adjust_sp_rtx = gen_add3_insn (stack_pointer_rtx,
-                                stack_pointer_rtx, GEN_INT (-saved_size));
+  adjust_sp_rtx =
+    gen_rtx_SET (stack_pointer_rtx,
+                gen_rtx_PLUS (GET_MODE(stack_pointer_rtx), stack_pointer_rtx, GEN_INT (-saved_size)));
   dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, adjust_sp_rtx,
                          dwarf);
   return dwarf;
@@ -5166,8 +5167,9 @@ riscv_adjust_libcall_cfi_epilogue ()
   int saved_size = cfun->machine->frame.save_libcall_adjustment;

   /* Debug info for adjust sp.  */
-  adjust_sp_rtx = gen_add3_insn (stack_pointer_rtx,
-                                stack_pointer_rtx, GEN_INT (saved_size));
+  adjust_sp_rtx =
+    gen_rtx_SET (stack_pointer_rtx,
+                gen_rtx_PLUS (GET_MODE(stack_pointer_rtx), stack_pointer_rtx, GEN_INT (saved_size)));
   dwarf = alloc_reg_note (REG_CFA_ADJUST_CFA, adjust_sp_rtx,
                          dwarf);

--
2.17.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-06  6:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06  6:56 [PATCH] [RISCV] Change the generation mode of `adjust_sp_rtx` from gen_insn to gen_SET jinma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).