public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] sra: Disqualify bases of operands of asm gotos
@ 2024-01-17 18:21 Martin Jambor
  2024-01-18  7:14 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambor @ 2024-01-17 18:21 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Biener

Hi,

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.

Bootstrapped and tested on x86_64-linux, OK for master?  It will need
some tweaking for release branches, is it in principle OK for them too
(after testing)?

Thanks,

Martin


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.
---
 gcc/testsuite/gcc.dg/torture/pr110422.c | 10 +++++++++
 gcc/tree-sra.cc                         | 29 ++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr110422.c

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 6a1141b7377..f8e71ec48b9 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -1559,15 +1559,32 @@ scan_function (void)
 	    case GIMPLE_ASM:
 	      {
 		gasm *asm_stmt = as_a <gasm *> (stmt);
-		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;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sra: Disqualify bases of operands of asm gotos
  2024-01-17 18:21 [PATCH] sra: Disqualify bases of operands of asm gotos Martin Jambor
@ 2024-01-18  7:14 ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2024-01-18  7:14 UTC (permalink / raw)
  To: Martin Jambor; +Cc: GCC Patches

On Wed, 17 Jan 2024, Martin Jambor wrote:

> Hi,
> 
> 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.
> 
> Bootstrapped and tested on x86_64-linux, OK for master?  It will need
> some tweaking for release branches, is it in principle OK for them too
> (after testing)?

OK.

> Thanks,
> 
> Martin
> 
> 
> 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.
> ---
>  gcc/testsuite/gcc.dg/torture/pr110422.c | 10 +++++++++
>  gcc/tree-sra.cc                         | 29 ++++++++++++++++++++-----
>  2 files changed, 33 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/torture/pr110422.c
> 
> 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 6a1141b7377..f8e71ec48b9 100644
> --- a/gcc/tree-sra.cc
> +++ b/gcc/tree-sra.cc
> @@ -1559,15 +1559,32 @@ scan_function (void)
>  	    case GIMPLE_ASM:
>  	      {
>  		gasm *asm_stmt = as_a <gasm *> (stmt);
> -		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;
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sra: Disqualify bases of operands of asm gotos
       [not found] <65a81ace.c80a0220.7bb5d.2f36SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2024-01-21 22:52 ` Jeff Law
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Law @ 2024-01-21 22:52 UTC (permalink / raw)
  To: Martin Jambor, GCC Patches; +Cc: Richard Biener



On 1/17/24 11:21, Martin Jambor wrote:
> Hi,
> 
> 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.
> 
> Bootstrapped and tested on x86_64-linux, OK for master?  It will need
> some tweaking for release branches, is it in principle OK for them too
> (after testing)?
> 
> Thanks,
> 
> Martin
> 
> 
> 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.
OK.  Also OK for the other release branches with necessary adjustments 
after testing.

jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-21 22:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 18:21 [PATCH] sra: Disqualify bases of operands of asm gotos Martin Jambor
2024-01-18  7:14 ` Richard Biener
     [not found] <65a81ace.c80a0220.7bb5d.2f36SMTPIN_ADDED_BROKEN@mx.google.com>
2024-01-21 22:52 ` Jeff Law

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).