[clang] [llvm] [openmp] [Clang][OpenMP] Implement Loop splitting `#pragma omp split` directive (PR #183261)
Amit Tiwari via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 04:48:09 PDT 2026
================
@@ -0,0 +1,40 @@
+/*
+ * Verify #pragma omp split counts(c1, c2, ...) at AST, IR, and runtime.
+ * counts(3, omp_fill, 2) with n=10 splits into: [0..3), [3..8), [8..10).
+ * Sum 0+1+...+9 = 45.
+ */
+// REQUIRES: x86-registered-target
+
+// 1) Syntax and semantics only
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// 2) AST dump should show OMPSplitDirective with OMPCountsClause node.
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-dump %s 2>&1 | FileCheck %s --check-prefix=AST
+
+// 3) Emit LLVM: three sequential loops
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=60 -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=IR
+
+
+int main(void) {
+ const int n = 10;
+ int sum = 0;
+
+#pragma omp split counts(3, omp_fill, 2)
+ for (int i = 0; i < n; ++i) {
+ sum += i;
+ }
+
+ return (sum == 45) ? 0 : 1;
+}
+
+// AST: OMPSplitDirective
+// AST: OMPCountsClause
+
+// IR: define
+// IR: .split.iv.0
+// IR: icmp slt i32 {{.*}}, 3
+// IR: .split.iv.1
+// IR: icmp slt i32 {{.*}}, 8
+// IR: .split.iv.2
+// IR: icmp slt i32 {{.*}}, 10
----------------
amitamd7 wrote:
Yep. Also added `split_codegen.cpp` for detailed checks.
https://github.com/llvm/llvm-project/pull/183261
More information about the llvm-commits
mailing list