[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-08 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #16 from Jakub Jelinek  ---
Fixed.

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-08 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #15 from GCC Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:8c0dd8a6ff85d6e7b38957f2da400f5cfa8fef6b

commit r14-7002-g8c0dd8a6ff85d6e7b38957f2da400f5cfa8fef6b
Author: Jakub Jelinek 
Date:   Mon Jan 8 13:59:15 2024 +0100

gimplify: Fix ICE in recalculate_side_effects [PR113228]

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.

2024-01-08  Jakub Jelinek  

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

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

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #14 from Andrew Pinski  ---
(In reply to Jakub Jelinek from comment #12)
> The reason why late gimplification/regimplification generally works fine
> with SSA_NAMEs is that the
> case SSA_NAME:
>   /* Allow callbacks into the gimplifier during optimization.  */
>   ret = GS_ALL_DONE;
>   break;
> case doesn't fall through into the recalculation.  It is just this new
> match.pd folding which can turn a tcc_comparison *expr_p (which is what
> generally wants to recalculate side-effects) into SSA_NAME (which isn't
> handled there).

Thanks for looking into this issue further and handling it.

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-05 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

Jakub Jelinek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #13 from Jakub Jelinek  ---
Created attachment 56991
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56991&action=edit
gcc14-pr113228.patch

So I'd just go with a simple patch to recalculate_side_effects.
Changing the case SSA_NAME: in gimplify_expr obviously isn't needed, that works
fine as is.

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-05 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #12 from Jakub Jelinek  ---
The reason why late gimplification/regimplification generally works fine with
SSA_NAMEs is that the
case SSA_NAME:
  /* Allow callbacks into the gimplifier during optimization.  */
  ret = GS_ALL_DONE;
  break;
case doesn't fall through into the recalculation.  It is just this new match.pd
folding which can turn a tcc_comparison *expr_p (which is what generally wants
to recalculate side-effects) into SSA_NAME (which isn't handled there).

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347 since r14-6420

2024-01-05 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

Jakub Jelinek  changed:

   What|Removed |Added

   Priority|P3  |P1
Summary|[14 Regression] ICE:|[14 Regression] ICE:
   |recalculate_side_effects,   |recalculate_side_effects,
   |at gimplify.cc:3347 |at gimplify.cc:3347 since
   ||r14-6420
 CC||jakub at gcc dot gnu.org

--- Comment #11 from Jakub Jelinek  ---
Confirmed this started with r14-6420-g85c5efcffed19ca6160eeecc2d4faebd9fee63aa
Reproduceable also on x86_64-linux with -O3.

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-04 Thread patrick at rivosinc dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #10 from Patrick O'Neill  ---
(In reply to Andrew Pinski from comment #9)
> Oh ok, I was deciding if I should look further into this or let someone else
> handle it. Since it is from a fuzzer, I am just going to say I don't have
> time to look into this latent bug even though I exposed it :).

Makes sense, I'll start adding a little blurb to future testcases that come
from the fuzzer so people can prioritize accordingly.

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-04 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #9 from Andrew Pinski  ---
(In reply to Patrick O'Neill from comment #8)
> (In reply to Andrew Pinski from comment #7)
> > This seems like a reduced testcase, where is the original testcase from? Or
> > is it an automated code generator?
> 
> This was found with the fuzzer we're using to try to nail down some spec
> fails in risc-v vector [1]. We've had some success with this approach.

Oh ok, I was deciding if I should look further into this or let someone else
handle it. Since it is from a fuzzer, I am just going to say I don't have time
to look into this latent bug even though I exposed it :).

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-04 Thread patrick at rivosinc dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #8 from Patrick O'Neill  ---
(In reply to Andrew Pinski from comment #7)
> This seems like a reduced testcase, where is the original testcase from? Or
> is it an automated code generator?

This was found with the fuzzer we're using to try to nail down some spec fails
in risc-v vector [1]. We've had some success with this approach.

I can share the unreduced testcase if that's interesting to you?

[1]: Csmith used w/ scripts to compare risc-v qemu with native build/runs:
https://github.com/patrick-rivos/gcc-fuzz-ci

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #7 from Andrew Pinski  ---
This seems like a reduced testcase, where is the original testcase from? Or is
it an automated code generator?

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #6 from Andrew Pinski  ---
What match is doing is correct, what reassoc is doing looks to be ok, but the
gimplifier just falls over on `SSA_NAME != 0`.

This fixes the ICE but I don't understand how the gimplifier was handling
SSA_NAME before if it ever was, the code mentioned here has not changed since
the tuples was merged in:
```
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 15b540646c2..0cbe159b383 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3304,6 +3304,9 @@ recalculate_side_effects (tree t)
   int len = TREE_OPERAND_LENGTH (t);
   int i;

+  if (code == SSA_NAME)
+return;
+
   switch (TREE_CODE_CLASS (code))
 {
 case tcc_expression:
@@ -18253,7 +18256,7 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p,
gimple_seq *post_p,
case SSA_NAME:
  /* Allow callbacks into the gimplifier during optimization.  */
  ret = GS_ALL_DONE;
- break;
+ goto dont_recalculate;

case OMP_PARALLEL:
  gimplify_omp_parallel (expr_p, pre_p);

```

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #5 from Andrew Pinski  ---
```
#6  0x00d4594f in force_gimple_operand_gsi (gsi=0x7fffd3c0,
expr=0x779fe6e0, simple_p=true, var=0x0, before=true, m=GSI_SAME_STMT) at
../../gcc/gimplify-me.cc:141
141   return force_gimple_operand_gsi_1 (gsi, expr,
(gdb) p expr
$1 = (tree) 0x779fe6e0
(gdb) p debug_tree(expr)
 
unit-size 
align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x77822b28 precision:1 min  max >

arg:0 
unit-size 
align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type
0x778225e8 precision:32 min  max

pointer_to_this >
visited var 
def_stmt k$0_17 = PHI <_23(4), 0(3)>
version:17
ptr-info 0x779ed390>
arg:1 
constant 0>
t.c:15:21 start: t.c:15:16 finish: t.c:15:24>
$2 = void
(gdb) p debug_generic_expr(expr)
k$0_17 != 0

```

Exactly what I had expected. and yes it is exposed by that ...

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #4 from Andrew Pinski  ---
(In reply to Patrick O'Neill from comment #1)
>   int k[3];

It would better if we didn't depend on an uninitialized variable (I have a
patch against reassoc to not handle uninitialized/undef names) and initializing
k as:
```
int k[3]={0,0,0};
```

Still shows the issue ...

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #3 from Andrew Pinski  ---
(gdb) p debug_tree(*expr_p)
 
unit-size 
align:32 warn_if_not_align:0 symtab:0 alias-set 2 canonical-type
0x7741c5e8 precision:32 min  max

pointer_to_this >
visited var 
def_stmt k$0_17 = PHI <_24(4), k$0_28(D)(3)>
version:17
ptr-info 0x77343cc0>

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2024-01-04
 Status|UNCONFIRMED |NEW

--- Comment #2 from Andrew Pinski  ---
Confirmed, I am 99% sure this was exposed by
r14-6420-g85c5efcffed19ca6160eeecc2d4faebd9fee63aa 

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |14.0

[Bug middle-end/113228] [14 Regression] ICE: recalculate_side_effects, at gimplify.cc:3347

2024-01-03 Thread patrick at rivosinc dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113228

--- Comment #1 from Patrick O'Neill  ---
Testcase:
int a;
long b;
signed c;
short d;
short i;
void f() {
  int k[3];
  int *l = &a;
  d = 0;
  for (; c; c--) {
i = 0;
for (; i <= 9; i++) {
  b = 1;
  for (; b <= 4; b++)
k[0] = k[0] == 0;
  *l |= k[d];
}
  }
}