public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] vregs: Fix up instantiate_virtual_regs_in_insn for asm goto with outputs [PR98603]
@ 2021-01-09  9:22 Jakub Jelinek
  2021-01-09  9:46 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-01-09  9:22 UTC (permalink / raw)
  To: Richard Biener, Jeff Law, Eric Botcazou, Vladimir Makarov; +Cc: gcc-patches

Hi!

If an asm insn fails constraint checking during vregs, it is just deleted.
We don't delete asm goto though because of the edges to the labels, so
instantiate_virtual_regs_in_insn would just remove the inputs and their
constraints, the pattern etc.
This worked fine when asm goto couldn't have output operands, but causes
ICEs later on when it has more than one output (and furthermore doesn't
really remove the problematic outputs).  The problem is that
for multiple outputs we have a PARALLEL with multiple ASM_OPERANDS, but
those must use the same ASM_OPERANDS_INPUT_VEC etc., but the code was
adjusting just one.

The following patch turns invalid asm goto into a bare
asm goto ("" : : : : lab, lab2, lab3);
i.e. no inputs/outputs/clobbers, just the labels.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-01-08  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/98603
	* function.c (instantiate_virtual_regs_in_insn): For asm goto
	with impossible constraints, drop all SETs, CLOBBERs, drop PARALLEL
	if any, set ASM_OPERANDS mode to VOIDmode and change
	ASM_OPERANDS_OUTPUT_CONSTRAINT and ASM_OPERANDS_OUTPUT_IDX.

	* gcc.target/i386/pr98603.c: New test.
	* gcc.target/aarch64/pr98603.c: New test.

--- gcc/function.c.jj	2021-01-04 10:25:37.929244060 +0100
+++ gcc/function.c	2021-01-08 15:28:42.864335347 +0100
@@ -1785,12 +1785,16 @@ instantiate_virtual_regs_in_insn (rtx_in
 	{
 	  error_for_asm (insn, "impossible constraint in %<asm%>");
 	  /* For asm goto, instead of fixing up all the edges
-	     just clear the template and clear input operands
-	     (asm goto doesn't have any output operands).  */
+	     just clear the template and clear input and output operands
+	     and strip away clobbers.  */
 	  if (JUMP_P (insn))
 	    {
 	      rtx asm_op = extract_asm_operands (PATTERN (insn));
+	      PATTERN (insn) = asm_op;
+	      PUT_MODE (asm_op, VOIDmode);
 	      ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup ("");
+	      ASM_OPERANDS_OUTPUT_CONSTRAINT (asm_op) = "";
+	      ASM_OPERANDS_OUTPUT_IDX (asm_op) = 0;
 	      ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0);
 	      ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0);
 	    }
--- gcc/testsuite/gcc.target/i386/pr98603.c.jj	2021-01-08 15:36:56.985764842 +0100
+++ gcc/testsuite/gcc.target/i386/pr98603.c	2021-01-08 15:36:44.301907830 +0100
@@ -0,0 +1,11 @@
+/* PR rtl-optimization/98603 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -w" } */
+
+int
+foo (void)
+{
+  int b, c;
+  asm goto ("" : "=r" (b), "=r" (c) : "I" (128) : : lab);	/* { dg-error "impossible constraint in 'asm'" } */
+lab:;
+}
--- gcc/testsuite/gcc.target/aarch64/pr98603.c.jj	2021-01-08 15:31:31.719431751 +0100
+++ gcc/testsuite/gcc.target/aarch64/pr98603.c	2021-01-08 15:31:05.343729099 +0100
@@ -0,0 +1,11 @@
+/* PR rtl-optimization/98603 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+int
+foo (void)
+{
+  int b, c;
+  asm goto ("" : "=R" (b), "=r" (c) : : : lab);	/* { dg-error "impossible constraint in 'asm'" } */
+lab:;
+}

	Jakub


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

* Re: [PATCH] vregs: Fix up instantiate_virtual_regs_in_insn for asm goto with outputs [PR98603]
  2021-01-09  9:22 [PATCH] vregs: Fix up instantiate_virtual_regs_in_insn for asm goto with outputs [PR98603] Jakub Jelinek
@ 2021-01-09  9:46 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-01-09  9:46 UTC (permalink / raw)
  To: Jakub Jelinek, Jeff Law, Eric Botcazou, Vladimir Makarov; +Cc: gcc-patches

On January 9, 2021 10:22:22 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>If an asm insn fails constraint checking during vregs, it is just
>deleted.
>We don't delete asm goto though because of the edges to the labels, so
>instantiate_virtual_regs_in_insn would just remove the inputs and their
>constraints, the pattern etc.
>This worked fine when asm goto couldn't have output operands, but
>causes
>ICEs later on when it has more than one output (and furthermore doesn't
>really remove the problematic outputs).  The problem is that
>for multiple outputs we have a PARALLEL with multiple ASM_OPERANDS, but
>those must use the same ASM_OPERANDS_INPUT_VEC etc., but the code was
>adjusting just one.
>
>The following patch turns invalid asm goto into a bare
>asm goto ("" : : : : lab, lab2, lab3);
>i.e. no inputs/outputs/clobbers, just the labels.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok. 

Richard. 

>2021-01-08  Jakub Jelinek  <jakub@redhat.com>
>
>	PR rtl-optimization/98603
>	* function.c (instantiate_virtual_regs_in_insn): For asm goto
>	with impossible constraints, drop all SETs, CLOBBERs, drop PARALLEL
>	if any, set ASM_OPERANDS mode to VOIDmode and change
>	ASM_OPERANDS_OUTPUT_CONSTRAINT and ASM_OPERANDS_OUTPUT_IDX.
>
>	* gcc.target/i386/pr98603.c: New test.
>	* gcc.target/aarch64/pr98603.c: New test.
>
>--- gcc/function.c.jj	2021-01-04 10:25:37.929244060 +0100
>+++ gcc/function.c	2021-01-08 15:28:42.864335347 +0100
>@@ -1785,12 +1785,16 @@ instantiate_virtual_regs_in_insn (rtx_in
> 	{
> 	  error_for_asm (insn, "impossible constraint in %<asm%>");
> 	  /* For asm goto, instead of fixing up all the edges
>-	     just clear the template and clear input operands
>-	     (asm goto doesn't have any output operands).  */
>+	     just clear the template and clear input and output operands
>+	     and strip away clobbers.  */
> 	  if (JUMP_P (insn))
> 	    {
> 	      rtx asm_op = extract_asm_operands (PATTERN (insn));
>+	      PATTERN (insn) = asm_op;
>+	      PUT_MODE (asm_op, VOIDmode);
> 	      ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup ("");
>+	      ASM_OPERANDS_OUTPUT_CONSTRAINT (asm_op) = "";
>+	      ASM_OPERANDS_OUTPUT_IDX (asm_op) = 0;
> 	      ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0);
> 	      ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0);
> 	    }
>--- gcc/testsuite/gcc.target/i386/pr98603.c.jj	2021-01-08
>15:36:56.985764842 +0100
>+++ gcc/testsuite/gcc.target/i386/pr98603.c	2021-01-08
>15:36:44.301907830 +0100
>@@ -0,0 +1,11 @@
>+/* PR rtl-optimization/98603 */
>+/* { dg-do compile } */
>+/* { dg-options "-O0 -w" } */
>+
>+int
>+foo (void)
>+{
>+  int b, c;
>+  asm goto ("" : "=r" (b), "=r" (c) : "I" (128) : : lab);	/* {
>dg-error "impossible constraint in 'asm'" } */
>+lab:;
>+}
>--- gcc/testsuite/gcc.target/aarch64/pr98603.c.jj	2021-01-08
>15:31:31.719431751 +0100
>+++ gcc/testsuite/gcc.target/aarch64/pr98603.c	2021-01-08
>15:31:05.343729099 +0100
>@@ -0,0 +1,11 @@
>+/* PR rtl-optimization/98603 */
>+/* { dg-do compile } */
>+/* { dg-options "-O0" } */
>+
>+int
>+foo (void)
>+{
>+  int b, c;
>+  asm goto ("" : "=R" (b), "=r" (c) : : : lab);	/* { dg-error
>"impossible constraint in 'asm'" } */
>+lab:;
>+}
>
>	Jakub


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

end of thread, other threads:[~2021-01-09  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09  9:22 [PATCH] vregs: Fix up instantiate_virtual_regs_in_insn for asm goto with outputs [PR98603] Jakub Jelinek
2021-01-09  9:46 ` Richard Biener

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