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 ipa/115097] Strange suboptimal codegen specifically at -O2 when copying struct type Date: Wed, 15 May 2024 07:24:44 +0000 [thread overview] Message-ID: <bug-115097-4-KpLwkCNHJ4@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-115097-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115097 --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- Testcase for the inliner issue: struct A { int a; short b; }; A test(A& a) { return a; } A test1(A& a) { return test(a); } where the issue is that test() doesn't use DECL_RESULT for its return and thus declare_return_variable setting up DECL_RESULT mapped to the call LHS doesn't help. And the reason why we don't use DECL_RESULT is that we have <return_expr 0x7ffff6bb0d40 type <void_type 0x7ffff6a30f18 void VOID align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff6a30f18 pointer_to_this <pointer_type 0x7ffff6a37000>> side-effects arg:0 <init_expr 0x7ffff6bb7fc8 type <record_type 0x7ffff6bbdbd0 A cxx-odr-p type_5 DI size <integer_cst 0x7ffff6a29240 constant 64> unit-size <integer_cst 0x7ffff6a29258 constant 8> align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff6bbdbd0 fields <function_decl 0x7ffff6bd5000 __dt > context <translation_unit_decl 0x7ffff6a18168 t2.ii> full-name "struct A" X() X(constX&) this=(X&) n_parents=0 use_template=0 interface-unknown pointer_to_this <pointer_type 0x7ffff6bbde70> reference_to_this <reference_type 0x7ffff6bbdd20> chain <type_decl 0x7ffff6a3ebe0 A>> side-effects arg:0 <result_decl 0x7ffff6bd1000 D.2798 type <record_type 0x7ffff6bbdbd0 A> ignored DI t2.ii:2:1 size <integer_cst 0x7ffff6a29240 64> unit-size <integer_cst 0x7ffff6a29258 8> align:32 warn_if_not_align:0 context <function_decl 0x7ffff6bc0500 test>> arg:1 <target_expr 0x7ffff6a09700 type <record_type 0x7ffff6bbdbd0 A> side-effects tree_3 arg:0 <var_decl 0x7ffff6a19cf0 D.2823> ... and gimplification changes the RESULT_DECL return because /* If aggregate_value_p is true, then we can return the bare RESULT_DECL. Recall that aggregate_value_p is FALSE for any aggregate type that is returned in registers. If we're returning values in registers, then we don't want to extend the lifetime of the RESULT_DECL, particularly across another call. In addition, for those aggregates for which hard_function_value generates a PARALLEL, we'll die during normal expansion of structure assignments; there's special code in expand_return to handle this case that does not exist in expand_expr. */ but the code does something else, using a new temporary register (here !aggregate_value_p). The following fixes that. diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index b0ed58ed0f9..e4cf5438e39 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1873,7 +1873,8 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p) to handle this case that does not exist in expand_expr. */ if (!result_decl) result = NULL_TREE; - else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl))) + else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl)) + || !is_gimple_reg_type (TREE_TYPE (result_decl))) { if (!poly_int_tree_p (DECL_SIZE (result_decl))) {
next prev parent reply other threads:[~2024-05-15 7:24 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-15 1:02 [Bug c/115097] New: " arthur.j.odwyer at gmail dot com 2024-05-15 6:50 ` [Bug tree-optimization/115097] " rguenth at gcc dot gnu.org 2024-05-15 7:05 ` [Bug ipa/115097] " rguenth at gcc dot gnu.org 2024-05-15 7:10 ` jakub at gcc dot gnu.org 2024-05-15 7:12 ` pinskia at gcc dot gnu.org 2024-05-15 7:24 ` rguenth at gcc dot gnu.org [this message] 2024-05-15 7:34 ` rguenth at gcc dot gnu.org 2024-05-15 9:05 ` hubicka at ucw dot cz
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-115097-4-KpLwkCNHJ4@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: linkBe 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).