Skip to content

Commit 46644ec

Browse files
committed
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 <[email protected]> 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.
1 parent 0d6f7b1 commit 46644ec

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

gcc/omp-expand.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,8 +2003,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
20032003
t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2),
20042004
unshare_expr (fd->loops[i].m1));
20052005
else if (fd->loops[i].m1)
2006-
t = fold_unary (NEGATE_EXPR, itype,
2007-
unshare_expr (fd->loops[i].m1));
2006+
t = fold_build1 (NEGATE_EXPR, itype,
2007+
unshare_expr (fd->loops[i].m1));
20082008
else
20092009
t = unshare_expr (fd->loops[i].m2);
20102010
tree m2minusm1
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* PR middle-end/108459 */
2+
3+
char a[17][17];
4+
5+
__attribute__((noipa)) void
6+
foo (int x, int y)
7+
{
8+
#pragma omp for collapse(2)
9+
for (int i = 1; i <= 16; i++)
10+
for (int j = i * x + y; j <= 16; j++)
11+
a[i][j] = 1;
12+
}
13+
14+
int
15+
main ()
16+
{
17+
#pragma omp parallel
18+
foo (1, 1);
19+
for (int i = 0; i <= 16; i++)
20+
for (int j = 0; j <= 16; j++)
21+
if (i >= 1 && j >= i + 1)
22+
{
23+
if (a[i][j] != 1)
24+
__builtin_abort ();
25+
a[i][j] = 0;
26+
}
27+
else if (a[i][j])
28+
__builtin_abort ();
29+
#pragma omp parallel
30+
foo (2, -2);
31+
for (int i = 0; i <= 16; i++)
32+
for (int j = 0; j <= 16; j++)
33+
if (i >= 1 && j >= 2 * i - 2)
34+
{
35+
if (a[i][j] != 1)
36+
__builtin_abort ();
37+
}
38+
else if (a[i][j])
39+
__builtin_abort ();
40+
return 0;
41+
}

0 commit comments

Comments
 (0)