[2/4] openmp: Fix initialization for 'unroll full'

Message ID 20230728130433.2377366-3-frederik@codesourcery.com
State New
Headers
Series openmp: loop transformation fixes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 warning Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_check--master-arm warning Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch failed to apply

Commit Message

Frederik Harwath July 28, 2023, 1:04 p.m. UTC
  The index variable initialization for the 'omp unroll'
directive with 'full' clause got lost and the testsuite
did not catch it.

Add the initialization and add -Wall to some tests
to detect uninitialized variable uses and other
potential problems in the code generation.

gcc/ChangeLog:

        * omp-transform-loops.cc (full_unroll): Add initialization of index variable.

libgomp/ChangeLog:

        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c:
        Use -Wall and add -Wno-unknown-pragmas to disable warnings about empty pragmas.
        Use -O2.
        * testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C:
        Copy of testsuite/libgomp.c-c++-common/matrix-no-directive-unroll-full-1.c,
        but using -O0 which works only for C++.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c: Use -Wall
        and use -Wno-unknown-pragmas to disable warnings about empty pragmas.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c:
        Likewise.
        * testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c:
        Likewise and fix broken function calls found by -Wall.
---
 gcc/omp-transform-loops.cc                          |  1 +
 .../matrix-no-directive-unroll-full-1.C             | 13 +++++++++++++
 .../loop-transforms/matrix-no-directive-1.c         |  2 +-
 .../matrix-no-directive-unroll-full-1.c             |  2 +-
 .../matrix-omp-distribute-parallel-for-1.c          |  2 ++
 .../loop-transforms/matrix-omp-for-1.c              |  2 +-
 .../loop-transforms/matrix-omp-parallel-for-1.c     |  2 +-
 .../matrix-omp-parallel-masked-taskloop-1.c         |  2 ++
 .../matrix-omp-parallel-masked-taskloop-simd-1.c    |  2 ++
 .../matrix-omp-target-parallel-for-1.c              |  2 +-
 ...rix-omp-target-teams-distribute-parallel-for-1.c |  2 ++
 .../loop-transforms/matrix-omp-taskloop-1.c         |  2 ++
 .../matrix-omp-teams-distribute-parallel-for-1.c    |  2 ++
 .../loop-transforms/matrix-simd-1.c                 |  2 ++
 .../libgomp.c-c++-common/loop-transforms/unroll-1.c |  8 +++++---
 .../loop-transforms/unroll-non-rect-1.c             |  2 ++
 16 files changed, 40 insertions(+), 8 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C

--
2.36.1

-----------------
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
  

Patch

diff --git a/gcc/omp-transform-loops.cc b/gcc/omp-transform-loops.cc
index 517faea537c..275a5260dae 100644
--- a/gcc/omp-transform-loops.cc
+++ b/gcc/omp-transform-loops.cc
@@ -548,6 +548,7 @@  full_unroll (gomp_for *omp_for, location_t loc, walk_ctx *ctx ATTRIBUTE_UNUSED)

   gimple_seq unrolled = NULL;
   gimple_seq_add_seq (&unrolled, gimple_omp_for_pre_body (omp_for));
+  gimplify_assign (index, init, &unrolled);
   push_gimplify_context ();
   gimple_seq_add_seq (&unrolled,
                      build_unroll_body (body, unroll_factor, index, incr));
diff --git a/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C b/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C
new file mode 100644
index 00000000000..3a684219627
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C
@@ -0,0 +1,13 @@ 
+/* { dg-additional-options { -O0 -fdump-tree-original -Wall -Wno-unknown-pragmas } } */
+
+#define COMMON_DIRECTIVE
+#define COMMON_TOP_TRANSFORM omp unroll full
+#define COLLAPSE_1
+#define COLLAPSE_2
+#define COLLAPSE_3
+#define IMPLEMENTATION_FILE "../../libgomp.c-c++-common/loop-transforms/matrix-constant-iter.h"
+
+#include "../../libgomp.c-c++-common/loop-transforms/matrix-transform-variants-1.h"
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "unroll_full" 13 "original" } } */
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c
index 9f7f02041b0..7904a5617f3 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c
@@ -1,4 +1,4 @@ 
-/* { dg-additional-options {-fdump-tree-original} } */
+/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */

 #define COMMON_DIRECTIVE
 #define COLLAPSE_1 collapse(1)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c
index 5dd0b5d2989..bd431a25102 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c
@@ -1,4 +1,4 @@ 
-/* { dg-additional-options {-fdump-tree-original} } */
+/* { dg-additional-options { -O2 -fdump-tree-original -Wall -Wno-unknown-pragmas } } */

 #define COMMON_DIRECTIVE
 #define COMMON_TOP_TRANSFORM omp unroll full
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c
index d855857e5ee..3875014dc96 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE "omp teams distribute parallel for"
 #define COLLAPSE_1 "collapse(1)"
 #define COLLAPSE_2 "collapse(2)"
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c
index f2a2b80b2fd..671396cd533 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c
@@ -1,4 +1,4 @@ 
-/* { dg-additional-options {-fdump-tree-original} } */
+/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */

 #define COMMON_DIRECTIVE omp for
 #define COLLAPSE_1 collapse(1)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c
index 2c5701efca4..cc66df42679 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c
@@ -1,4 +1,4 @@ 
-/* { dg-additional-options {-fdump-tree-original} } */
+/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */

 #define COMMON_DIRECTIVE omp parallel for
 #define COLLAPSE_1 collapse(1)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c
index e2def212725..890b460f374 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp parallel masked taskloop
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c
index ce601555cfb..74f6271504a 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp parallel masked taskloop simd
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c
index 365b39ba385..8138ea57f38 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c
@@ -1,4 +1,4 @@ 
-/* { dg-additional-options {-fdump-tree-original} } */
+/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */

 #define COMMON_DIRECTIVE omp target parallel for map(tofrom:result[0:dim0*dim1]) map(to:matrix1[0:dim0*dim1], matrix2[0:dim0*dim1])
 #define COLLAPSE_1 collapse(1)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c
index 8afe34874c9..d4d162d9c2b 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp target teams distribute parallel for map(tofrom:result[:dim0*dim1]) map(to:matrix1[0:dim0*dim1], matrix2[0:dim0*dim1])
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c
index bbc78b39db0..28edb6ce83e 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp taskloop
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c
index 3a58e479374..481a20a18d0 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp teams distribute parallel for
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c
index e5155dcf76d..200ddd859f5 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #define COMMON_DIRECTIVE omp simd
 #define COLLAPSE_1 collapse(1)
 #define COLLAPSE_2 collapse(2)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c
index 2ac0fff16af..eb5d3d77eb8 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #include <stdio.h>

 int compute_sum1 ()
@@ -11,7 +13,7 @@  int compute_sum1 ()
     sum++;

   if (j != 7)
-    __builtin_abort;
+    __builtin_abort ();

   return sum;
 }
@@ -27,7 +29,7 @@  int compute_sum2()
     sum++;

   if (j != 7)
-    __builtin_abort;
+    __builtin_abort ();

   return sum;
 }
@@ -43,7 +45,7 @@  int compute_sum3()
     sum++;

   if (j != 7)
-    __builtin_abort;
+    __builtin_abort ();

   return sum;
 }
diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c
index 2f9924aea1f..7bd9b906235 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */
+
 #include <stdio.h>
 #include <stdlib.h>