public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/27800] extra temprorary created when gimplifying return
Date: Tue, 20 Feb 2024 10:46:34 +0000	[thread overview]
Message-ID: <bug-27800-4-BAfoAX5Q3u@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-27800-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27800

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note this is done on purpose, possibly to better handle functions with multiple
returns.

A fix is probably in gimplification of the MODIFY_EXPR

  D.2774 = a != 0 ? b : c

where gimplify_cond_expr isn't told it can re-use the LHS as temporary.
That means special-casing this COND_EXPR RHS in gimplify_modify_expr_rhs
which already handles the non-register type case.  It could be extended
to cover all cases which then generates the smaller

int iii (int a, int b, int c)
{
  int D.2774;

  if (a != 0) goto <D.2775>; else goto <D.2776>;
  <D.2775>:
  D.2774 = b;
  goto <D.2777>;
  <D.2776>:
  D.2774 = c;
  <D.2777>:
  return D.2774;
}

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 76221f7637d..b48c43f1471 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -5985,7 +5985,7 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p,
tree *to_p,
             down into the branches.  This is mandatory for ADDRESSABLE types,
             since we cannot generate temporaries for such, but it saves a
             copy in other cases as well.  */
-         if (!is_gimple_reg_type (TREE_TYPE (*from_p)))
+         if (1)
            {
              /* This code should mirror the code in gimplify_cond_expr. */
              enum tree_code code = TREE_CODE (*expr_p);

or to cases where is_gimple_reg (*to_p).

  parent reply	other threads:[~2024-02-20 10:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-27800-4@http.gcc.gnu.org/bugzilla/>
2021-07-24  5:35 ` pinskia at gcc dot gnu.org
2023-02-06 12:16 ` rguenth at gcc dot gnu.org
2024-02-20 10:46 ` rguenth at gcc dot gnu.org [this message]
2024-05-07 12:20 ` cvs-commit at gcc dot gnu.org
2024-05-07 12:20 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-27800-4-BAfoAX5Q3u@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).