public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gimplify: Fix ICE in recalculate_side_effects [PR113228]
@ 2024-01-06  8:41 Jakub Jelinek
  2024-01-08 11:34 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-01-06  8:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

The following testcase ICEs during regimplificatgion since the addition of
(convert (eqne zero_one_valued_p@0 INTEGER_CST@1))
simplification.  That simplification is novel in the sense that in
gimplify_expr it can turn an expression (comparison in particular) into
a SSA_NAME.  Normally when gimplify_expr sees originally a SSA_NAME, it does
        case SSA_NAME:
          /* Allow callbacks into the gimplifier during optimization.  */
          ret = GS_ALL_DONE;
          break;
and doesn't try to recalculate side effects because of that, but in this
case gimplify_expr normally enters the:
        default:
          switch (TREE_CODE_CLASS (TREE_CODE (*expr_p)))
            {
            case tcc_comparison:
then does
                      *expr_p = gimple_boolify (*expr_p);
and then
                          *expr_p = fold_convert_loc (input_location,
                                                      org_type, *expr_p);
with this new match.pd simplification turns that tcc_comparison class
into SSA_NAME.  Unlike the outer SSA_NAME handling though, this falls
through into
          recalculate_side_effects (*expr_p);

        dont_recalculate:
          break;
but unfortunately recalculate_side_effects doesn't handle SSA_NAME and ICEs
on it.
SSA_NAMEs don't ever have TREE_SIDE_EFFECTS set on those, so the following
patch fixes it by handling it similarly to the tcc_constant case.

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

2024-01-06  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/113228
	* gimplify.cc (recalculate_side_effects): Do nothing for SSA_NAMEs.

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

--- gcc/gimplify.cc.jj	2024-01-03 11:51:40.744603324 +0100
+++ gcc/gimplify.cc	2024-01-05 13:32:34.351336320 +0100
@@ -3344,6 +3344,9 @@ recalculate_side_effects (tree t)
       return;
 
     default:
+      if (code == SSA_NAME)
+	/* No side-effects.  */
+	return;
       gcc_unreachable ();
    }
 }
--- gcc/testsuite/gcc.c-torture/compile/pr113228.c.jj	2024-01-05 13:27:42.876330301 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr113228.c	2024-01-05 13:27:22.503609458 +0100
@@ -0,0 +1,17 @@
+/* PR tree-optimization/113228 */
+
+int a, b, c, d, i;
+
+void
+foo (void)
+{
+  int k[3] = {};
+  int *l = &a;
+  for (d = 0; c; c--)
+    for (i = 0; i <= 9; i++)
+      {
+	for (b = 1; b <= 4; b++)
+	  k[0] = k[0] == 0;
+	*l |= k[d];
+      }
+}

	Jakub


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

* Re: [PATCH] gimplify: Fix ICE in recalculate_side_effects [PR113228]
  2024-01-06  8:41 [PATCH] gimplify: Fix ICE in recalculate_side_effects [PR113228] Jakub Jelinek
@ 2024-01-08 11:34 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-01-08 11:34 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Sat, 6 Jan 2024, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase ICEs during regimplificatgion since the addition of
> (convert (eqne zero_one_valued_p@0 INTEGER_CST@1))
> simplification.  That simplification is novel in the sense that in
> gimplify_expr it can turn an expression (comparison in particular) into
> a SSA_NAME.  Normally when gimplify_expr sees originally a SSA_NAME, it does
>         case SSA_NAME:
>           /* Allow callbacks into the gimplifier during optimization.  */
>           ret = GS_ALL_DONE;
>           break;
> and doesn't try to recalculate side effects because of that, but in this
> case gimplify_expr normally enters the:
>         default:
>           switch (TREE_CODE_CLASS (TREE_CODE (*expr_p)))
>             {
>             case tcc_comparison:
> then does
>                       *expr_p = gimple_boolify (*expr_p);
> and then
>                           *expr_p = fold_convert_loc (input_location,
>                                                       org_type, *expr_p);
> with this new match.pd simplification turns that tcc_comparison class
> into SSA_NAME.  Unlike the outer SSA_NAME handling though, this falls
> through into
>           recalculate_side_effects (*expr_p);
> 
>         dont_recalculate:
>           break;
> but unfortunately recalculate_side_effects doesn't handle SSA_NAME and ICEs
> on it.
> SSA_NAMEs don't ever have TREE_SIDE_EFFECTS set on those, so the following
> patch fixes it by handling it similarly to the tcc_constant case.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2024-01-06  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/113228
> 	* gimplify.cc (recalculate_side_effects): Do nothing for SSA_NAMEs.
> 
> 	* gcc.c-torture/compile/pr113228.c: New test.
> 
> --- gcc/gimplify.cc.jj	2024-01-03 11:51:40.744603324 +0100
> +++ gcc/gimplify.cc	2024-01-05 13:32:34.351336320 +0100
> @@ -3344,6 +3344,9 @@ recalculate_side_effects (tree t)
>        return;
>  
>      default:
> +      if (code == SSA_NAME)
> +	/* No side-effects.  */
> +	return;
>        gcc_unreachable ();
>     }
>  }
> --- gcc/testsuite/gcc.c-torture/compile/pr113228.c.jj	2024-01-05 13:27:42.876330301 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr113228.c	2024-01-05 13:27:22.503609458 +0100
> @@ -0,0 +1,17 @@
> +/* PR tree-optimization/113228 */
> +
> +int a, b, c, d, i;
> +
> +void
> +foo (void)
> +{
> +  int k[3] = {};
> +  int *l = &a;
> +  for (d = 0; c; c--)
> +    for (i = 0; i <= 9; i++)
> +      {
> +	for (b = 1; b <= 4; b++)
> +	  k[0] = k[0] == 0;
> +	*l |= k[d];
> +      }
> +}
> 
> 	Jakub
> 
> 

-- 
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] 2+ messages in thread

end of thread, other threads:[~2024-01-08 11:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-06  8:41 [PATCH] gimplify: Fix ICE in recalculate_side_effects [PR113228] Jakub Jelinek
2024-01-08 11:34 ` 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).