[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-05-02 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #9 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:23d16b36eb41366841af052c35f335f35ee203cc

commit r11-10699-g23d16b36eb41366841af052c35f335f35ee203cc
Author: Jakub Jelinek 
Date:   Thu Jan 19 21:00:08 2023 +0100

openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

expand_omp_for_init_counts was using for the case where collapse(2)
inner loop has init expression dependent on non-constant multiple of
the outer iterator and the condition upper bound expression doesn't
depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
will just return NULL if it can't be folded, we need fold_build1
instead.

2023-01-19  Jakub Jelinek  

PR middle-end/108459
* omp-expand.c (expand_omp_for_init_counts): Use fold_build1 rather
than fold_unary for NEGATE_EXPR.

* testsuite/libgomp.c/pr108459.c: New test.

(cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88)

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-02-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #8 from CVS Commits  ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:629907bff87e238d45afe609716880e8acf9e541

commit r12-9141-g629907bff87e238d45afe609716880e8acf9e541
Author: Jakub Jelinek 
Date:   Thu Jan 19 21:00:08 2023 +0100

openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

expand_omp_for_init_counts was using for the case where collapse(2)
inner loop has init expression dependent on non-constant multiple of
the outer iterator and the condition upper bound expression doesn't
depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
will just return NULL if it can't be folded, we need fold_build1
instead.

2023-01-19  Jakub Jelinek  

PR middle-end/108459
* omp-expand.cc (expand_omp_for_init_counts): Use fold_build1
rather
than fold_unary for NEGATE_EXPR.

* testsuite/libgomp.c/pr108459.c: New test.

(cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88)

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #7 from Jakub Jelinek  ---
Fixed on the trunk, will backport later.

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:46644ec99cb355845b23bb1d02775c057ed8ee88

commit r13-5262-g46644ec99cb355845b23bb1d02775c057ed8ee88
Author: Jakub Jelinek 
Date:   Thu Jan 19 21:00:08 2023 +0100

openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

expand_omp_for_init_counts was using for the case where collapse(2)
inner loop has init expression dependent on non-constant multiple of
the outer iterator and the condition upper bound expression doesn't
depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
will just return NULL if it can't be folded, we need fold_build1
instead.

2023-01-19  Jakub Jelinek  

PR middle-end/108459
* omp-expand.cc (expand_omp_for_init_counts): Use fold_build1
rather
than fold_unary for NEGATE_EXPR.

* testsuite/libgomp.c/pr108459.c: New test.

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
   Last reconfirmed||2023-01-19
 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED

--- Comment #5 from Jakub Jelinek  ---
Created attachment 54305
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54305=edit
gcc13-pr108459.patch

Full untested patch.

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #4 from Jakub Jelinek  ---
I think that ought to be fine.
There is
  if (single_nonrect == -1
  || (loop->m1 && TREE_CODE (loop->m1) != INTEGER_CST)
  || (loop->m2 && TREE_CODE (loop->m2) != INTEGER_CST)
  || TREE_CODE (loop->n1) != INTEGER_CST
  || TREE_CODE (loop->n2) != INTEGER_CST
  || TREE_CODE (loop->step) != INTEGER_CST)
{
  count = NULL_TREE;
  continue;
}
some lines above that, after all, it is also using fold_binary rather than
fold_build2 etc.  All that code is there to compute the constant number of
iterations and other helper values for non-rectangular loops with all constant
expressions.

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #3 from Tobias Burnus  ---
(In reply to Jakub Jelinek from comment #2)
> --- gcc/omp-expand.cc.jj  2023-01-02 09:32:49.399894958 +0100
> +++ gcc/omp-expand.cc 2023-01-19 12:01:05.103410564 +0100
> - t = fold_unary (NEGATE_EXPR, itype,
> - unshare_expr (fd->loops[i].m1));
> + t = fold_build1 (NEGATE_EXPR, itype,
> +  unshare_expr (fd->loops[i].m1));

Confirmed - fold_unary only hands constants, fold_build1 calls the same but if
it fails (i.e. "tem == NULL"), it calls then
  build1_loc (loc, code, type, op0 PASS_MEM_STAT);

Question: Is the following needed or not? I have not fully followed whether
"diff" and/or "ostep" could be a non-constant or not. At a glance, it looks as
if a variable could be possible.

--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -730,5 +730,4 @@ omp_extract_for_data (gomp_for *for_stmt, struct
omp_for_data *fd,
diff = fold_binary (TRUNC_DIV_EXPR, itype,
-   fold_unary (NEGATE_EXPR, itype, diff),
-   fold_unary (NEGATE_EXPR, itype,
-   ostep));
+   build1 (NEGATE_EXPR, itype, diff),
+   build1 (NEGATE_EXPR, itype, ostep));
  else

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #2 from Jakub Jelinek  ---
--- gcc/omp-expand.cc.jj2023-01-02 09:32:49.399894958 +0100
+++ gcc/omp-expand.cc   2023-01-19 12:01:05.103410564 +0100
@@ -2003,8 +2003,8 @@ expand_omp_for_init_counts (struct omp_f
t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2),
 unshare_expr (fd->loops[i].m1));
  else if (fd->loops[i].m1)
-   t = fold_unary (NEGATE_EXPR, itype,
-   unshare_expr (fd->loops[i].m1));
+   t = fold_build1 (NEGATE_EXPR, itype,
+unshare_expr (fd->loops[i].m1));
  else
t = unshare_expr (fd->loops[i].m2);
  tree m2minusm1
fixes this, just need to play with testcases.

[Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts

2023-01-19 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108459

--- Comment #1 from Jakub Jelinek  ---
Slightly simplified:
void
foo (int x)
{
  #pragma omp for collapse(2)
  for (int i = 1; i <= 16; i++)
for (int j = i * x; j <= 16; j++)
  ;
}

Started with my r11-2537-g29e0ad452cdf001bcc commit, will have a look.