public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] expand: Don't reuse DEBUG_EXPRs with vector type if they have different modes [PR100508]
@ 2021-05-12  8:11 Jakub Jelinek
  2021-05-12  8:28 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-05-12  8:11 UTC (permalink / raw)
  To: Richard Biener, Eric Botcazou, Jeff Law; +Cc: gcc-patches

Hi!

The inliner doesn't remap DEBUG_EXPR_DECLs, so the same decls can appear
in multiple functions.
Furthermore, expansion reuses corresponding DEBUG_EXPRs too, so they again
can be reused in multiple functions.
Neither of that is a major problem, DEBUG_EXPRs are just magic value holders
and what value they stand for is independent in each function and driven by
what debug stmts or DEBUG_INSNs they are bound to.
Except for DEBUG_EXPR*s with vector types, TYPE_MODE can be either BLKmode
or some vector mode depending on whether current function's enabled ISAs
support that vector mode or not.  On the following testcase, we expand it
first in foo function without AVX2 enabled and so the DEBUG_EXPR is
BLKmode, but later the same DEBUG_EXPR_DECL is used in a simd clone with
AVX2 enabled and expansion ICEs because of a mode mismatch.

The following patch fixes that by forcing recreation of a DEBUG_EXPR if
there is a mode mismatch for vector typed DEBUG_EXPR_DECL, DEBUG_EXPRs
will be still reused in between functions otherwise and within the same
function the mode should be always the same.

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

2021-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/100508
	* cfgexpand.c (expand_debug_expr): For DEBUG_EXPR_DECL with vector
	type, don't reuse DECL_RTL if it has different mode, instead force
	creation of a new DEBUG_EXPR.

	* gcc.dg/gomp/pr100508.c: New test.

--- gcc/cfgexpand.c.jj	2021-05-10 12:22:30.127455200 +0200
+++ gcc/cfgexpand.c	2021-05-11 10:33:31.446450828 +0200
@@ -4512,7 +4512,12 @@ expand_debug_expr (tree exp)
       op0 = DECL_RTL_IF_SET (exp);
 
       if (op0)
-	return op0;
+	{
+	  if (GET_MODE (op0) != mode)
+	    gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
+	  else
+	    return op0;
+	}
 
       op0 = gen_rtx_DEBUG_EXPR (mode);
       DEBUG_EXPR_TREE_DECL (op0) = exp;
--- gcc/testsuite/gcc.dg/gomp/pr100508.c.jj	2021-05-11 11:18:08.561067214 +0200
+++ gcc/testsuite/gcc.dg/gomp/pr100508.c	2021-05-11 11:17:39.520374736 +0200
@@ -0,0 +1,14 @@
+/* PR middle-end/100508 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -fopenmp-simd" } */
+
+typedef int __attribute__((__vector_size__(32))) V;
+V j;
+
+#pragma omp declare simd
+int
+foo (void)
+{
+  V m = j;
+  return 0;
+}

	Jakub


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

* Re: [PATCH] expand: Don't reuse DEBUG_EXPRs with vector type if they have different modes [PR100508]
  2021-05-12  8:11 [PATCH] expand: Don't reuse DEBUG_EXPRs with vector type if they have different modes [PR100508] Jakub Jelinek
@ 2021-05-12  8:28 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-05-12  8:28 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Eric Botcazou, Jeff Law, gcc-patches

On Wed, 12 May 2021, Jakub Jelinek wrote:

> Hi!
> 
> The inliner doesn't remap DEBUG_EXPR_DECLs, so the same decls can appear
> in multiple functions.
> Furthermore, expansion reuses corresponding DEBUG_EXPRs too, so they again
> can be reused in multiple functions.
> Neither of that is a major problem, DEBUG_EXPRs are just magic value holders
> and what value they stand for is independent in each function and driven by
> what debug stmts or DEBUG_INSNs they are bound to.
> Except for DEBUG_EXPR*s with vector types, TYPE_MODE can be either BLKmode
> or some vector mode depending on whether current function's enabled ISAs
> support that vector mode or not.  On the following testcase, we expand it
> first in foo function without AVX2 enabled and so the DEBUG_EXPR is
> BLKmode, but later the same DEBUG_EXPR_DECL is used in a simd clone with
> AVX2 enabled and expansion ICEs because of a mode mismatch.

Ah, I wasn't aware we're doing this.

> The following patch fixes that by forcing recreation of a DEBUG_EXPR if
> there is a mode mismatch for vector typed DEBUG_EXPR_DECL, DEBUG_EXPRs
> will be still reused in between functions otherwise and within the same
> function the mode should be always the same.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK

Thanks,
Richard.

> 2021-05-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/100508
> 	* cfgexpand.c (expand_debug_expr): For DEBUG_EXPR_DECL with vector
> 	type, don't reuse DECL_RTL if it has different mode, instead force
> 	creation of a new DEBUG_EXPR.
> 
> 	* gcc.dg/gomp/pr100508.c: New test.
> 
> --- gcc/cfgexpand.c.jj	2021-05-10 12:22:30.127455200 +0200
> +++ gcc/cfgexpand.c	2021-05-11 10:33:31.446450828 +0200
> @@ -4512,7 +4512,12 @@ expand_debug_expr (tree exp)
>        op0 = DECL_RTL_IF_SET (exp);
>  
>        if (op0)
> -	return op0;
> +	{
> +	  if (GET_MODE (op0) != mode)
> +	    gcc_assert (VECTOR_TYPE_P (TREE_TYPE (exp)));
> +	  else
> +	    return op0;
> +	}
>  
>        op0 = gen_rtx_DEBUG_EXPR (mode);
>        DEBUG_EXPR_TREE_DECL (op0) = exp;
> --- gcc/testsuite/gcc.dg/gomp/pr100508.c.jj	2021-05-11 11:18:08.561067214 +0200
> +++ gcc/testsuite/gcc.dg/gomp/pr100508.c	2021-05-11 11:17:39.520374736 +0200
> @@ -0,0 +1,14 @@
> +/* PR middle-end/100508 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -g -fopenmp-simd" } */
> +
> +typedef int __attribute__((__vector_size__(32))) V;
> +V j;
> +
> +#pragma omp declare simd
> +int
> +foo (void)
> +{
> +  V m = j;
> +  return 0;
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2021-05-12  8:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  8:11 [PATCH] expand: Don't reuse DEBUG_EXPRs with vector type if they have different modes [PR100508] Jakub Jelinek
2021-05-12  8:28 ` 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).