public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7666] aarch64: Fix up RTL sharing bug in aarch64_load_symref_appropriately [PR104910]
Date: Wed, 16 Mar 2022 10:04:52 +0000 (GMT)	[thread overview]
Message-ID: <20220316100452.D77453857806@sourceware.org> (raw)

https://gcc.gnu.org/g:952155629ca1a4dfe7c7b26e53d118a9b853ed4a

commit r12-7666-g952155629ca1a4dfe7c7b26e53d118a9b853ed4a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 16 11:04:16 2022 +0100

    aarch64: Fix up RTL sharing bug in aarch64_load_symref_appropriately [PR104910]
    
    We unshare all RTL created during expansion, but when
    aarch64_load_symref_appropriately is called after expansion like in the
    following testcases, we use imm in both HIGH and LO_SUM operands.
    If imm is some RTL that shouldn't be shared like a non-sharable CONST,
    we get at least with --enable-checking=rtl a checking ICE, otherwise might
    just get silently wrong code.
    
    The following patch fixes that by copying it if it can't be shared.
    
    2022-03-16  Jakub Jelinek  <jakub@redhat.com>
    
            PR target/104910
            * config/aarch64/aarch64.cc (aarch64_load_symref_appropriately): Copy
            imm rtx.
    
            * gcc.dg/pr104910.c: New test.

Diff:
---
 gcc/config/aarch64/aarch64.cc   |  2 +-
 gcc/testsuite/gcc.dg/pr104910.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index dbeaaf484db..7a0337591f5 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -3971,7 +3971,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 	if (can_create_pseudo_p ())
 	  tmp_reg = gen_reg_rtx (mode);
 
-	emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
+	emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm)));
 	emit_insn (gen_add_losym (dest, tmp_reg, imm));
 	return;
       }
diff --git a/gcc/testsuite/gcc.dg/pr104910.c b/gcc/testsuite/gcc.dg/pr104910.c
new file mode 100644
index 00000000000..10fed8147de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104910.c
@@ -0,0 +1,14 @@
+/* PR target/104910 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fno-forward-propagate" } */
+/* { dg-additional-options "-fstack-protector-all" { target fstack_protector } } */
+
+void
+bar (void);
+
+void
+foo (int x)
+{
+  if (x)
+    bar ();
+}


                 reply	other threads:[~2022-03-16 10:04 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=20220316100452.D77453857806@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@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).