public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Jambor <jamborm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-8246] sra: Disqualify bases of operands of asm gotos
Date: Wed, 24 Jan 2024 19:37:50 +0000 (GMT)	[thread overview]
Message-ID: <20240124193750.C456D3858420@sourceware.org> (raw)

https://gcc.gnu.org/g:2b7204c52392c1c0da9c91a5feae0c44018a6f37

commit r13-8246-g2b7204c52392c1c0da9c91a5feae0c44018a6f37
Author: Martin Jambor <mjambor@suse.cz>
Date:   Wed Jan 24 20:35:00 2024 +0100

    sra: Disqualify bases of operands of asm gotos
    
    PR 110422 shows that SRA can ICE assuming there is a single edge
    outgoing from a block terminated with an asm goto.  We need that for
    BB-terminating statements so that any adjustments they make to the
    aggregates can be copied over to their replacements.  Because we can't
    have that after ASM gotos, we need to punt.
    
    gcc/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * tree-sra.cc (scan_function): Disqualify bases of operands of asm
            gotos.
    
    gcc/testsuite/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * gcc.dg/torture/pr110422.c: New test.
    
    (cherry picked from commit 6764043e88a4208f7c69bf0ccd19ddc7a6016fb1)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr110422.c | 10 ++++++++++
 gcc/tree-sra.cc                         | 29 +++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr110422.c b/gcc/testsuite/gcc.dg/torture/pr110422.c
new file mode 100644
index 00000000000..2e171a7a19e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110422.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+struct T { int x; };
+int foo(void) {
+  struct T v;
+  asm goto("" : "+r"(v.x) : : : lab);
+  return 0;
+lab:
+  return -5;
+}
diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index ad0c738645d..7fdc3bb957d 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -1413,15 +1413,32 @@ scan_function (void)
 		gasm *asm_stmt = as_a <gasm *> (stmt);
 		walk_stmt_load_store_addr_ops (asm_stmt, NULL, NULL, NULL,
 					       asm_visit_addr);
-		for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+		if (stmt_ends_bb_p (asm_stmt)
+		    && !single_succ_p (gimple_bb (asm_stmt)))
 		  {
-		    t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
-		    ret |= build_access_from_expr (t, asm_stmt, false);
+		    for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+		      {
+			t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
+			disqualify_base_of_expr (t, "OP of asm goto.");
+		      }
+		    for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+		      {
+			t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
+			disqualify_base_of_expr (t, "OP of asm goto.");
+		      }
 		  }
-		for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+		else
 		  {
-		    t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
-		    ret |= build_access_from_expr (t, asm_stmt, true);
+		    for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+		      {
+			t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
+			ret |= build_access_from_expr (t, asm_stmt, false);
+		      }
+		    for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+		      {
+			t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
+			ret |= build_access_from_expr (t, asm_stmt, true);
+		      }
 		  }
 	      }
 	      break;

                 reply	other threads:[~2024-01-24 19:37 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=20240124193750.C456D3858420@sourceware.org \
    --to=jamborm@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).