xtensa: Fix the regression introduce by abe81aa19f250516fd57f76cad9c0920cce221bc

Message ID 3b6c25bd-2e0a-468c-b202-d2de3a8779f3@yahoo.co.jp
State New
Headers
Series xtensa: Fix the regression introduce by abe81aa19f250516fd57f76cad9c0920cce221bc |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Takayuki 'January June' Suwa July 19, 2024, 8:35 p.m. UTC
  It is not wrong but also not optimal to specify that sibcalls require
register A0 in RTX generation pass, by misleading DFA into thinking it
is being used in function body.
It would be better to specify it in pro_and_epilogue as with 'return'
insn in order to avoid incorrect removing load that restores A0 in
subsequent passes, but since it is not possible to modify each sibcall
there, as a workaround we will preface it with a 'use' as before.

This patch effectively reverts commit abe81aa19f250516fd57f76cad9c0920cce221bc.

gcc/ChangeLog:

	* config/xtensa/xtensa-protos.h (xtensa_expand_call):
	Remove the third argument.
	* config/xtensa/xtensa.cc (xtensa_expand_call):
	Remove the third argument and the code that uses it.
	* config/xtensa/xtensa.md (call, call_value, sibcall, sibcall_value):
	Remove each Boolean constant specified in the third argument of
	xtensa_expand_call.
	(sibcall_epilogue): Add emitting '(use A0_REG)' after calling
	xtensa_expand_epilogue.
---
  gcc/config/xtensa/xtensa-protos.h |  2 +-
  gcc/config/xtensa/xtensa.cc       | 10 +---------
  gcc/config/xtensa/xtensa.md       |  9 +++++----
  3 files changed, 7 insertions(+), 14 deletions(-)
  

Comments

Max Filippov July 30, 2024, 6:11 a.m. UTC | #1
On Fri, Jul 19, 2024 at 1:35 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> It is not wrong but also not optimal to specify that sibcalls require
> register A0 in RTX generation pass, by misleading DFA into thinking it
> is being used in function body.
> It would be better to specify it in pro_and_epilogue as with 'return'
> insn in order to avoid incorrect removing load that restores A0 in
> subsequent passes, but since it is not possible to modify each sibcall
> there, as a workaround we will preface it with a 'use' as before.
>
> This patch effectively reverts commit abe81aa19f250516fd57f76cad9c0920cce221bc.
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa-protos.h (xtensa_expand_call):
>         Remove the third argument.
>         * config/xtensa/xtensa.cc (xtensa_expand_call):
>         Remove the third argument and the code that uses it.
>         * config/xtensa/xtensa.md (call, call_value, sibcall, sibcall_value):
>         Remove each Boolean constant specified in the third argument of
>         xtensa_expand_call.
>         (sibcall_epilogue): Add emitting '(use A0_REG)' after calling
>         xtensa_expand_epilogue.
> ---
>   gcc/config/xtensa/xtensa-protos.h |  2 +-
>   gcc/config/xtensa/xtensa.cc       | 10 +---------
>   gcc/config/xtensa/xtensa.md       |  9 +++++----
>   3 files changed, 7 insertions(+), 14 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master
  

Patch

diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h
index 8f645e87de9..3646ceaa093 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -53,7 +53,7 @@  extern void xtensa_expand_atomic (enum rtx_code, rtx, rtx, rtx, bool);
  extern void xtensa_emit_loop_end (rtx_insn *, rtx *);
  extern char *xtensa_emit_branch (bool, rtx *);
  extern char *xtensa_emit_movcc (bool, bool, bool, rtx *);
-extern void xtensa_expand_call (int, rtx *, bool);
+extern void xtensa_expand_call (int, rtx *);
  extern char *xtensa_emit_call (int, rtx *);
  extern char *xtensa_emit_sibcall (int, rtx *);
  extern bool xtensa_tls_referenced_p (rtx);
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index d49d224466a..431e3627e9f 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -2301,7 +2301,7 @@  xtensa_emit_movcc (bool inverted, bool isfp, bool isbool, rtx *operands)
  
  
  void
-xtensa_expand_call (int callop, rtx *operands, bool sibcall_p)
+xtensa_expand_call (int callop, rtx *operands)
  {
    rtx call;
    rtx_insn *call_insn;
@@ -2343,14 +2343,6 @@  xtensa_expand_call (int callop, rtx *operands, bool sibcall_p)
        CALL_INSN_FUNCTION_USAGE (call_insn) =
  	gen_rtx_EXPR_LIST (Pmode, clob, CALL_INSN_FUNCTION_USAGE (call_insn));
      }
-  else if (sibcall_p)
-    {
-      /* Sibling call requires a return address to the caller, similar to
-	 "return" insn.  */
-      rtx use = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, A0_REG));
-      CALL_INSN_FUNCTION_USAGE (call_insn) =
-	gen_rtx_EXPR_LIST (Pmode, use, CALL_INSN_FUNCTION_USAGE (call_insn));
-    }
  }
  
  
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 8709ef6d7a7..d074792575e 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -2565,7 +2565,7 @@ 
  	 (match_operand 1 "" ""))]
    ""
  {
-  xtensa_expand_call (0, operands, false);
+  xtensa_expand_call (0, operands);
    DONE;
  })
  
@@ -2586,7 +2586,7 @@ 
  	      (match_operand 2 "" "")))]
    ""
  {
-  xtensa_expand_call (1, operands, false);
+  xtensa_expand_call (1, operands);
    DONE;
  })
  
@@ -2607,7 +2607,7 @@ 
  	 (match_operand 1 "" ""))]
    "!TARGET_WINDOWED_ABI"
  {
-  xtensa_expand_call (0, operands, true);
+  xtensa_expand_call (0, operands);
    DONE;
  })
  
@@ -2628,7 +2628,7 @@ 
  	      (match_operand 2 "" "")))]
    "!TARGET_WINDOWED_ABI"
  {
-  xtensa_expand_call (1, operands, true);
+  xtensa_expand_call (1, operands);
    DONE;
  })
  
@@ -2745,6 +2745,7 @@ 
    "!TARGET_WINDOWED_ABI"
  {
    xtensa_expand_epilogue ();
+  emit_use (gen_rtx_REG (SImode, A0_REG));
    DONE;
  })