From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Avoid more invalid GIMPLE with register bases
Date: Fri, 28 Apr 2023 09:48:01 +0000 (UTC) [thread overview]
Message-ID: <20230428094801.-9M393A-UKtY2sP48CW9oaENltg5QuCvAJuDB3s0NEU@z> (raw)
The Ada frontend, for example with gnat.dg/inline2_pkg.adb, tends
to create VIEW_CONVERT expressions with aggregate type even of
non-aggregate entities. In this case for example
return <retval> = (BIT_FIELD_REF <VIEW_CONVERT_EXPR<struct inline2_pkg__ieee_short_real>(number), 16, 16> & 32640) != 32640;
currently gimplification and SSA rewrite turn this into
_1 = BIT_FIELD_REF <VIEW_CONVERT_EXPR<struct inline2_pkg__ieee_short_real>(number_2(D));
which is two operations on a register. While as seen with PR109652
we might not want to completely rule out register to aggregate type
VIEW_CONVERTs we definitely do not want to stack multiple ops here.
The solution is to make sure the gimplifier puts a non-register as
the base object. For the above this will add
number.1 = number;
and use number.1 in the compound reference. Code generation is
unchanged, FRE optimizes this to BIT_FIELD_REF <number_2(D), ...>.
I think BIT_FIELD_REF <VIEW_CONVERT (x), ...> could be always
rewritten into BIT_FIELD_REF <x, ...>, but that's a separate thing.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
* gimplify.cc (gimplify_compound_lval): When there's a
non-register type produced by one of the handled component
operations make sure we get a non-register base.
---
gcc/gimplify.cc | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index c38a962dd04..3740a8979af 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3264,6 +3264,11 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
}
need_non_reg = true;
}
+ else if (!is_gimple_reg_type (TREE_TYPE (t)))
+ /* When the result of an operation, in particular a VIEW_CONVERT_EXPR
+ is a non-register type then require the base object to be a
+ non-register as well. */
+ need_non_reg = true;
}
/* Step 2 is to gimplify the base expression. Make sure lvalue is set
--
2.35.3
reply other threads:[~2023-04-28 9:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230428094801.-9M393A-UKtY2sP48CW9oaENltg5QuCvAJuDB3s0NEU@z \
--to=rguenther@suse.de \
--cc=gcc-patches@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).