[flang-commits] [flang] [flang][OpenMP] Lower DO, SIMD, and DO SIMD metadirective variants (PR #218555)
via flang-commits
flang-commits at lists.llvm.org
Mon Aug 24 20:57:41 PDT 2026
================
@@ -0,0 +1,562 @@
+! Test lowering of metadirectives with ordinary loop-associated variants.
+
+! RUN: %flang_fc1 -fopenmp -emit-hlfir -fopenmp-version=52 %s -o - | FileCheck %s
+
+! CHECK: #loop_unroll = #llvm.loop_unroll<disable = false, count = 4 : i64>
+! CHECK: #loop_annotation = #llvm.loop_annotation<unroll = #loop_unroll>
+
+! CHECK-LABEL: func.func @_QPtest_do(
+! CHECK-NOT: omp.parallel
+! CHECK: omp.wsloop
+! CHECK: omp.loop_nest
+! CHECK: hlfir.assign
+! CHECK: omp.yield
+! CHECK: return
+subroutine test_do(n, a)
+ integer :: n, a(n), i
+ !$omp metadirective &
+ !$omp & when(implementation={vendor(llvm)}: do) &
+ !$omp & otherwise(nothing)
+ do i = 1, n
+ a(i) = i
+ end do
+end subroutine
+
+! CHECK-LABEL: func.func @_QPtest_simd(
+! CHECK-NOT: omp.wsloop
+! CHECK: omp.simd linear(
+! CHECK: omp.loop_nest
+! CHECK: hlfir.assign
+! CHECK: omp.yield
+! CHECK-NOT: fir.do_loop
+! CHECK: fir.load
+! CHECK: hlfir.assign
+! CHECK: return
+subroutine test_simd(n, a, after)
+ integer :: n, a(n), after, i
+ !$omp metadirective &
+ !$omp & when(implementation={vendor(llvm)}: simd) &
+ !$omp & otherwise(nothing)
+ do i = 1, n
+ a(i) = i
+ end do
+ after = i
+end subroutine
+
+! CHECK-LABEL: func.func @_QPtest_do_simd(
+! CHECK-NOT: omp.parallel
+! CHECK: omp.wsloop
+! CHECK: omp.simd linear(
+! CHECK: omp.loop_nest
+! CHECK: hlfir.assign
+! CHECK: omp.yield
+! CHECK: return
+subroutine test_do_simd(n, a)
+ integer :: n, a(n), i
+ !$omp metadirective &
+ !$omp & when(implementation={vendor(llvm)}: do simd) &
+ !$omp & otherwise(nothing)
+ do i = 1, n
+ a(i) = i
+ end do
+end subroutine
+
+! CHECK-LABEL: func.func @_QPtest_begin_do(
+! CHECK: fir.if {{.*}} {
+! CHECK: omp.wsloop
+! CHECK: omp.loop_nest
+! CHECK: hlfir.assign
+! CHECK: } else {
+! CHECK-NOT: omp.
+! CHECK: fir.do_loop
+! CHECK: hlfir.assign
+! CHECK: }
+! CHECK: return
----------------
MattPD wrote:
The `test_begin_do` CHECK block still passes when the checked output contains a third `fir.do_loop` between the `fir.if` and the `return` for `test_begin_do`. The checks therefore do not detect a duplicate associated loop after the `fir.if`.
Could bounded `CHECK-NOT` lines exclude two kinds of operations in that range: `fir.do_loop` and OpenMP loop operations? The test would then prove that lowering emits the associated loop only once.
https://github.com/llvm/llvm-project/pull/218555
More information about the flang-commits
mailing list