[clang] [llvm] [openmp] [Clang][OpenMP] Add `#pragma omp flatten` loop directive + `depth` clause (PR #206977)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 02:56:04 PDT 2026


================
@@ -0,0 +1,41 @@
+// RUN: %libomp-compile -fopenmp-version=61 && %libomp-run \
+// RUN:   | FileCheck %s --match-full-lines
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+  int I = -1;
+  int J = -1;
+
+#pragma omp flatten
+  for (I = 0; I < 2; ++I)
+    for (J = 0; J < 3; ++J)
+      if (I == 1 && J == 2)
+        continue;
+
+  printf("i=%d j=%d\n", I, J);
+
+#pragma omp flatten
+  for (I = 5; I > 0; I -= 2)
+    for (J = 7; J > 1; J -= 3)
+      ;
+
+  printf("descending-i=%d descending-j=%d\n", I, J);
+
+  // An empty inner loop executes no body, but the outer loop still runs to
+  // completion, so 'I' reaches its final value while 'J' keeps the value from
+  // its initialization.
+  int Zero = 0;
+#pragma omp flatten
+  for (I = 0; I < 3; ++I)
+    for (J = 0; J < Zero; ++J)
+      ;
+
+  printf("empty-inner-i=%d empty-inner-j=%d\n", I, J);
+  return EXIT_SUCCESS;
+}
+
+// CHECK:      i=2 j=3
----------------
Meinersbur wrote:

[nit] Variable names are upper case but printed lower case?

https://github.com/llvm/llvm-project/pull/206977


More information about the llvm-commits mailing list