public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9885] aarch64: Fix return register handling in untyped_call
@ 2023-09-20 10:13 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2023-09-20 10:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:38d0605ac8bc90324170041676fc05e7e595769e

commit r12-9885-g38d0605ac8bc90324170041676fc05e7e595769e
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Sep 20 11:13:19 2023 +0100

    aarch64: Fix return register handling in untyped_call
    
    While working on another patch, I hit a problem with the aarch64
    expansion of untyped_call.  The expander emits the usual:
    
      (set (mem ...) (reg resN))
    
    instructions to store the result registers to memory, but it didn't
    say in RTL where those resN results came from.  This eventually led
    to a failure of gcc.dg/torture/stackalign/builtin-return-2.c,
    via regrename.
    
    This patch turns the untyped call from a plain call to a call_value,
    to represent that the call returns (or might return) a useful value.
    The patch also uses a PARALLEL return rtx to represent all the possible
    return registers.
    
    gcc/
            * config/aarch64/aarch64.md (untyped_call): Emit a call_value
            rather than a call.  List each possible destination register
            in the call pattern.
    
    (cherry picked from commit 629efe27744d13c3b83bbe8338b84c37c83dbe4f)

Diff:
---
 gcc/config/aarch64/aarch64.md | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index b9b3ba4f916..cd568f3daa0 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -1159,9 +1159,27 @@
 {
   int i;
 
+  /* Generate a PARALLEL that contains all of the register results.
+     The offsets are somewhat arbitrary, since we don't know the
+     actual return type.  The main thing we need to avoid is having
+     overlapping byte ranges, since those might give the impression
+     that two registers are known to have data in common.  */
+  rtvec rets = rtvec_alloc (XVECLEN (operands[2], 0));
+  poly_int64 offset = 0;
+  for (i = 0; i < XVECLEN (operands[2], 0); i++)
+    {
+      rtx reg = SET_SRC (XVECEXP (operands[2], 0, i));
+      gcc_assert (REG_P (reg));
+      rtx offset_rtx = gen_int_mode (offset, Pmode);
+      rtx piece = gen_rtx_EXPR_LIST (VOIDmode, reg, offset_rtx);
+      RTVEC_ELT (rets, i) = piece;
+      offset += GET_MODE_SIZE (GET_MODE (reg));
+    }
+  rtx ret = gen_rtx_PARALLEL (VOIDmode, rets);
+
   /* Untyped calls always use the default ABI.  It's only possible to use
      ABI variants if we know the type of the target function.  */
-  emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
+  emit_call_insn (gen_call_value (ret, operands[0], const0_rtx, const0_rtx));
 
   for (i = 0; i < XVECLEN (operands[2], 0); i++)
     {

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

only message in thread, other threads:[~2023-09-20 10:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 10:13 [gcc r12-9885] aarch64: Fix return register handling in untyped_call Richard Sandiford

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).