Add libgomp.c-c++-common/pr106449-2.c (was: [committed] openmp: Fix up handling of non-rectangular simd loops with pointer type iterators [PR106449])

Message ID 21e39473-5bcc-02a0-fc64-564e0a606ac2@codesourcery.com
State New
Headers
Series Add libgomp.c-c++-common/pr106449-2.c (was: [committed] openmp: Fix up handling of non-rectangular simd loops with pointer type iterators [PR106449]) |

Commit Message

Tobias Burnus July 29, 2022, 9:48 a.m. UTC
  On 29.07.22 10:03, Jakub Jelinek wrote:
> There were 2 issues visible on this new testcase, one that we didn't have
> special POINTER_TYPE_P handling in a few spots of expand_omp_simd ...
> The other issue was that we put n2 expression directly into a
> comparison in a condition and regimplified that, for the &a[512] case that
> and with gimplification being destructed that unfortunately meant modification
> of original fd->loops[?].n2.  Fixed by unsharing the expression.

I created a testcase for the non-simd case – and due to messing up, it failed;
hence, I filled PR middle-end/106467.  After fixing the testcase, it passes.
(→ closed PR as invalid).

However, given that the testcase now exists, I think it makes sense to add it :-)

Changes compared to the simd testcase: replaced '(parallel for) simd' by 'for',
removed 'linear', used now 'b' and 'c' instead of storing both ptrs in 'b'.

Side remark: Before GCC 12, GCC complained about "q = p + n" with
"error: initializer expression refers to iteration variable ‘p’".

OK for mainline?

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Comments

Jakub Jelinek July 29, 2022, 10:34 a.m. UTC | #1
On Fri, Jul 29, 2022 at 11:48:08AM +0200, Tobias Burnus wrote:
> On 29.07.22 10:03, Jakub Jelinek wrote:
> > There were 2 issues visible on this new testcase, one that we didn't have
> > special POINTER_TYPE_P handling in a few spots of expand_omp_simd ...
> > The other issue was that we put n2 expression directly into a
> > comparison in a condition and regimplified that, for the &a[512] case that
> > and with gimplification being destructed that unfortunately meant modification
> > of original fd->loops[?].n2.  Fixed by unsharing the expression.
> 
> I created a testcase for the non-simd case – and due to messing up, it failed;
> hence, I filled PR middle-end/106467.  After fixing the testcase, it passes.
> (→ closed PR as invalid).
> 
> However, given that the testcase now exists, I think it makes sense to add it :-)
> 
> Changes compared to the simd testcase: replaced '(parallel for) simd' by 'for',
> removed 'linear', used now 'b' and 'c' instead of storing both ptrs in 'b'.
> 
> Side remark: Before GCC 12, GCC complained about "q = p + n" with
> "error: initializer expression refers to iteration variable ‘p’".
> 
> OK for mainline?

Ok, thanks.

	Jakub
  

Patch

Add libgomp.c-c++-common/pr106449-2.c

This run-time test test pointer-based iteration with collapse,
similar to the '(parallel) simd' test for PR106449 but for 'for'.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/pr106449-2.c: New test.

 .../testsuite/libgomp.c-c++-common/pr106449-2.c    | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr106449-2.c b/libgomp/testsuite/libgomp.c-c++-common/pr106449-2.c
new file mode 100644
index 00000000000..7fef7461bcf
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/pr106449-2.c
@@ -0,0 +1,64 @@ 
+/* { dg-do run } */
+
+/* Based on pr106449.c - but using 'for' instead of 'simd'.
+   Cf. PR middle-end/106449 (for pr106449.c) and PR middle-end/106467.  */
+
+void
+foo (void)
+{
+  int a[1024], *b[65536], *c[65536];
+  int *p, *q, **r = &b[0], **r2 = &c[0], i;
+  #pragma omp for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = p + 64; q < p + 128; q++)
+      {
+	*r++ = p;
+	*r2++ = q;
+      }
+  for (i = 0; i < 32768; i++)
+    if (b[i] != &a[i / 64] || c[i] != &a[(i / 64) + 64 + (i % 64)])
+      __builtin_abort ();
+}
+
+void
+bar (int n, int m)
+{
+  int a[1024], *b[32768], *c[32768];
+  int *p, *q, **r = &b[0], **r2 = &c[0], i;
+  #pragma omp for collapse(2)
+  for (p = &a[0]; p < &a[512]; p++)
+    for (q = p + n; q < p + m; q++)
+      {
+	*r++ = p;
+	*r2++ = q;
+      }
+  for (i = 0; i < 32768; i++)
+    if (b[i] != &a[i / 64] || c[i] != &a[(i / 64) + 64 + (i % 64)])
+      __builtin_abort ();
+}
+
+void
+baz (int n, int m)
+{
+  int a[1024], *b[8192], *c[8192];
+  int *p, *q, **r = &b[0], **r2 = &c[0], i;
+  #pragma omp for collapse(2)
+  for (p = &a[0]; p < &a[512]; p += 4)
+    for (q = p + n; q < p + m; q += 2)
+      {
+	*r++ = p;
+	*r2++ = q;
+      }
+  for (i = 0; i < 4096; i++)
+    if (b[i] != &a[(i / 32) * 4] || c[i] != &a[(i / 32) * 4 + 64 + (i % 32) * 2])
+      __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo ();
+  bar (64, 128);
+  baz (64, 128);
+  return 0;
+}