public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921)
@ 2013-01-09 23:47 Jakub Jelinek
  2013-01-10  9:19 ` Richard Biener
  2013-01-11 13:04 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Jelinek @ 2013-01-09 23:47 UTC (permalink / raw)
  To: Richard Biener, Richard Henderson; +Cc: gcc-patches

Hi!

We weren't processing GIMPLE_ASMs that set complex SSA_NAMEs, which lead to
SSA_NAMEs with NULL SSA_NAME_DEF_STMT, either leading to crashes or silent
wrong code, depending on --enable-checking.  Fixed thusly,
bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-01-09  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/55921
	* tree-complex.c (expand_complex_asm): New function.
	(expand_complex_operations_1): Call it for GIMPLE_ASM.

	* gcc.c-torture/compile/pr55921.c: New test.

--- gcc/tree-complex.c.jj	2013-01-04 13:44:35.000000000 +0100
+++ gcc/tree-complex.c	2013-01-09 20:34:55.595674683 +0100
@@ -1391,6 +1391,36 @@ expand_complex_comparison (gimple_stmt_i
   update_stmt (stmt);
 }
 
+/* Expand inline asm that sets some complex SSA_NAMEs.  */
+
+static void
+expand_complex_asm (gimple_stmt_iterator *gsi)
+{
+  gimple stmt = gsi_stmt (*gsi);
+  unsigned int i;
+
+  for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
+    {
+      tree link = gimple_asm_output_op (stmt, i);
+      tree op = TREE_VALUE (link);
+      if (TREE_CODE (op) == SSA_NAME
+	  && TREE_CODE (TREE_TYPE (op)) == COMPLEX_TYPE)
+	{
+	  tree type = TREE_TYPE (op);
+	  tree inner_type = TREE_TYPE (type);
+	  tree r = build1 (REALPART_EXPR, inner_type, op);
+	  tree i = build1 (IMAGPART_EXPR, inner_type, op);
+	  gimple_seq list = set_component_ssa_name (op, false, r);
+
+	  if (list)
+	    gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
+
+	  list = set_component_ssa_name (op, true, i);
+	  if (list)
+	    gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
+	}
+    }
+}
 
 /* Process one statement.  If we identify a complex operation, expand it.  */
 
@@ -1403,6 +1433,12 @@ expand_complex_operations_1 (gimple_stmt
   complex_lattice_t al, bl;
   enum tree_code code;
 
+  if (gimple_code (stmt) == GIMPLE_ASM)
+    {
+      expand_complex_asm (gsi);
+      return;
+    }
+
   lhs = gimple_get_lhs (stmt);
   if (!lhs && gimple_code (stmt) != GIMPLE_COND)
     return;
--- gcc/testsuite/gcc.c-torture/compile/pr55921.c.jj	2013-01-09 20:37:33.643755543 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr55921.c	2013-01-09 20:37:07.000000000 +0100
@@ -0,0 +1,21 @@
+/* PR tree-optimization/55921 */
+
+typedef union
+{
+  _Complex float cf;
+  long long ll;
+} ucf;
+
+void
+foo (ucf *in, ucf *out, _Complex float r)
+{
+  int i;
+  ucf ucf1;
+  _Complex float cf;
+
+  ucf1.ll = in[i].ll;
+  __asm ("" : "=r" (cf) : "0" (ucf1.ll));
+  cf *= r;
+  __asm ("" : "=r" (ucf1.ll) : "0" (cf));
+  out[i].ll = ucf1.ll;
+}

	Jakub

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

* Re: [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921)
  2013-01-09 23:47 [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921) Jakub Jelinek
@ 2013-01-10  9:19 ` Richard Biener
  2013-01-11 13:04 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2013-01-10  9:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Henderson, gcc-patches

On Thu, 10 Jan 2013, Jakub Jelinek wrote:

> Hi!
> 
> We weren't processing GIMPLE_ASMs that set complex SSA_NAMEs, which lead to
> SSA_NAMEs with NULL SSA_NAME_DEF_STMT, either leading to crashes or silent
> wrong code, depending on --enable-checking.  Fixed thusly,
> bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2013-01-09  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/55921
> 	* tree-complex.c (expand_complex_asm): New function.
> 	(expand_complex_operations_1): Call it for GIMPLE_ASM.
> 
> 	* gcc.c-torture/compile/pr55921.c: New test.
> 
> --- gcc/tree-complex.c.jj	2013-01-04 13:44:35.000000000 +0100
> +++ gcc/tree-complex.c	2013-01-09 20:34:55.595674683 +0100
> @@ -1391,6 +1391,36 @@ expand_complex_comparison (gimple_stmt_i
>    update_stmt (stmt);
>  }
>  
> +/* Expand inline asm that sets some complex SSA_NAMEs.  */
> +
> +static void
> +expand_complex_asm (gimple_stmt_iterator *gsi)
> +{
> +  gimple stmt = gsi_stmt (*gsi);
> +  unsigned int i;
> +
> +  for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
> +    {
> +      tree link = gimple_asm_output_op (stmt, i);
> +      tree op = TREE_VALUE (link);
> +      if (TREE_CODE (op) == SSA_NAME
> +	  && TREE_CODE (TREE_TYPE (op)) == COMPLEX_TYPE)
> +	{
> +	  tree type = TREE_TYPE (op);
> +	  tree inner_type = TREE_TYPE (type);
> +	  tree r = build1 (REALPART_EXPR, inner_type, op);
> +	  tree i = build1 (IMAGPART_EXPR, inner_type, op);
> +	  gimple_seq list = set_component_ssa_name (op, false, r);
> +
> +	  if (list)
> +	    gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
> +
> +	  list = set_component_ssa_name (op, true, i);
> +	  if (list)
> +	    gsi_insert_seq_after (gsi, list, GSI_CONTINUE_LINKING);
> +	}
> +    }
> +}
>  
>  /* Process one statement.  If we identify a complex operation, expand it.  */
>  
> @@ -1403,6 +1433,12 @@ expand_complex_operations_1 (gimple_stmt
>    complex_lattice_t al, bl;
>    enum tree_code code;
>  
> +  if (gimple_code (stmt) == GIMPLE_ASM)
> +    {
> +      expand_complex_asm (gsi);
> +      return;
> +    }
> +
>    lhs = gimple_get_lhs (stmt);
>    if (!lhs && gimple_code (stmt) != GIMPLE_COND)
>      return;
> --- gcc/testsuite/gcc.c-torture/compile/pr55921.c.jj	2013-01-09 20:37:33.643755543 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr55921.c	2013-01-09 20:37:07.000000000 +0100
> @@ -0,0 +1,21 @@
> +/* PR tree-optimization/55921 */
> +
> +typedef union
> +{
> +  _Complex float cf;
> +  long long ll;
> +} ucf;
> +
> +void
> +foo (ucf *in, ucf *out, _Complex float r)
> +{
> +  int i;
> +  ucf ucf1;
> +  _Complex float cf;
> +
> +  ucf1.ll = in[i].ll;
> +  __asm ("" : "=r" (cf) : "0" (ucf1.ll));
> +  cf *= r;
> +  __asm ("" : "=r" (ucf1.ll) : "0" (cf));
> +  out[i].ll = ucf1.ll;
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend

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

* Re: [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921)
  2013-01-09 23:47 [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921) Jakub Jelinek
  2013-01-10  9:19 ` Richard Biener
@ 2013-01-11 13:04 ` Andreas Schwab
  2013-01-11 13:05   ` Richard Biener
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2013-01-11 13:04 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, Richard Henderson, gcc-patches

Jakub Jelinek <jakub@redhat.com> writes:

> +  __asm ("" : "=r" (cf) : "0" (ucf1.ll));

gcc/testsuite/gcc.c-torture/compile/pr55921.c:17:3: error: 'asm' operand has impossible constraints
gcc/testsuite/gcc.c-torture/compile/pr55921.c:19:3: error: 'asm' operand has impossible constraints

OK?  This still triggers the original bug.

Andreas.

2013-01-11  Andreas Schwab  <schwab@linux-m68k.org>

	* gcc.c-torture/compile/pr55921.c: Don't use matching constraints.

diff --git a/gcc/testsuite/gcc.c-torture/compile/pr55921.c b/gcc/testsuite/gcc.c-torture/compile/pr55921.c
index 8ac9e9b..94b7bce 100644
--- a/gcc/testsuite/gcc.c-torture/compile/pr55921.c
+++ b/gcc/testsuite/gcc.c-torture/compile/pr55921.c
@@ -14,8 +14,8 @@ foo (ucf *in, ucf *out, _Complex float r)
   _Complex float cf;
 
   ucf1.ll = in[i].ll;
-  __asm ("" : "=r" (cf) : "0" (ucf1.ll));
+  __asm ("" : "=r" (cf) : "r" (ucf1.ll));
   cf *= r;
-  __asm ("" : "=r" (ucf1.ll) : "0" (cf));
+  __asm ("" : "=r" (ucf1.ll) : "r" (cf));
   out[i].ll = ucf1.ll;
 }

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921)
  2013-01-11 13:04 ` Andreas Schwab
@ 2013-01-11 13:05   ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2013-01-11 13:05 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Jakub Jelinek, Richard Henderson, gcc-patches

On Fri, 11 Jan 2013, Andreas Schwab wrote:

> Jakub Jelinek <jakub@redhat.com> writes:
> 
> > +  __asm ("" : "=r" (cf) : "0" (ucf1.ll));
> 
> gcc/testsuite/gcc.c-torture/compile/pr55921.c:17:3: error: 'asm' operand has impossible constraints
> gcc/testsuite/gcc.c-torture/compile/pr55921.c:19:3: error: 'asm' operand has impossible constraints
> 
> OK?  This still triggers the original bug.

Ok.

Thanks,
Richard.

> Andreas.
> 
> 2013-01-11  Andreas Schwab  <schwab@linux-m68k.org>
> 
> 	* gcc.c-torture/compile/pr55921.c: Don't use matching constraints.
> 
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr55921.c b/gcc/testsuite/gcc.c-torture/compile/pr55921.c
> index 8ac9e9b..94b7bce 100644
> --- a/gcc/testsuite/gcc.c-torture/compile/pr55921.c
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr55921.c
> @@ -14,8 +14,8 @@ foo (ucf *in, ucf *out, _Complex float r)
>    _Complex float cf;
>  
>    ucf1.ll = in[i].ll;
> -  __asm ("" : "=r" (cf) : "0" (ucf1.ll));
> +  __asm ("" : "=r" (cf) : "r" (ucf1.ll));
>    cf *= r;
> -  __asm ("" : "=r" (ucf1.ll) : "0" (cf));
> +  __asm ("" : "=r" (ucf1.ll) : "r" (cf));
>    out[i].ll = ucf1.ll;
>  }
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend

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

end of thread, other threads:[~2013-01-11 13:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-09 23:47 [PATCH] Fix complex lowering with inline asm (PR tree-optimization/55921) Jakub Jelinek
2013-01-10  9:19 ` Richard Biener
2013-01-11 13:04 ` Andreas Schwab
2013-01-11 13:05   ` 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).