[llvm-branch-commits] [clang] [CIR][OpenMP] Add initial support for the 'distribute' directive (PR #232781)

Jan Leyonberg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 4 12:55:34 PST 2026


https://github.com/jsjodin updated https://github.com/llvm/llvm-project/pull/232781

>From 24b2e438dae1e1dff1fca2904bf5348d1be35b3c Mon Sep 17 00:00:00 2001
From: Jan Leyonberg <jan_sjodin at yahoo.com>
Date: Wed, 7 Oct 2026 14:09:55 -0400
Subject: [PATCH] [CIR][OpenMP] Add initial support for distribute

This patch adds initial support for the OpenMP 'distribute' directive. Basic
code generation for the standalone and combined cases is introduced. Support
for clauses will be added in the future. The composite 'teams distribute
parallel for' form will be added in a subsequent patch.

Assisted-by: Cursor / Claude Sonnet 5 High
---
 clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp    | 167 ++++-
 .../CIR/CodeGenOpenMP/not-yet-implemented.c   |  12 +
 .../CodeGenOpenMP/target-teams-distribute.c   | 708 ++++++++++++++++++
 .../test/CIR/CodeGenOpenMP/teams-distribute.c | 191 +++++
 4 files changed, 1052 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/CIR/CodeGenOpenMP/target-teams-distribute.c
 create mode 100644 clang/test/CIR/CodeGenOpenMP/teams-distribute.c

diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index 531e6492c8c659..7d3a9f5e2210bd 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -71,6 +71,7 @@ static bool isCombinableLeaf(llvm::omp::Directive dir) {
   case llvm::omp::OMPD_parallel:
   case llvm::omp::OMPD_teams:
   case llvm::omp::OMPD_for:
+  case llvm::omp::OMPD_distribute:
     return true;
   default:
     return false;
@@ -115,6 +116,34 @@ static bool isTargetSPMD(const OMPExecutableDirective &s) {
   }
 }
 
+/// Returns true if \p s is (or is equivalent to) a `target teams distribute`
+/// construct: the combined form, or any mix of explicit nesting and
+/// combined forms of `target`, `teams`, and `distribute`.
+static bool isTargetTeamsDistribute(const OMPExecutableDirective &s) {
+  if (s.getDirectiveKind() == llvm::omp::OMPD_target_teams_distribute)
+    return true;
+
+  const OMPExecutableDirective *teams = nullptr;
+  if (s.getDirectiveKind() == llvm::omp::OMPD_target_teams) {
+    teams = &s;
+  } else if (s.getDirectiveKind() == llvm::omp::OMPD_target) {
+    teams = getSingleNestedOMPDirective(s);
+    if (!teams)
+      return false;
+    if (teams->getDirectiveKind() == llvm::omp::OMPD_teams_distribute)
+      return true;
+    if (teams->getDirectiveKind() != llvm::omp::OMPD_teams)
+      return false;
+  } else {
+    return false;
+  }
+
+  const OMPExecutableDirective *distribute =
+      getSingleNestedOMPDirective(*teams);
+  return distribute &&
+         distribute->getDirectiveKind() == llvm::omp::OMPD_distribute;
+}
+
 static mlir::LogicalResult
 emitParallelClauses(CIRGenFunction &cgf, CIRGenModule &cgm,
                     CIRGenBuilderTy &builder, mlir::Location loc,
@@ -436,23 +465,16 @@ emitHostEvalLoopBounds(CIRGenFunction &cgf, const OMPLoopDirective &s) {
   return hev;
 }
 
-/// Lowers an OMPLoopDirective's `for` directive to an omp.wsloop +
-/// omp.loop_nest.
-static mlir::LogicalResult
-emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
-                       omp::ConstructQueue::const_iterator item) {
+/// Lowers an OMPLoopDirective to an omp.loop_nest wrapped by an \p OpTy
+/// (omp.wsloop or omp.distribute).
+template <typename OpTy, typename OperandsTy>
+static mlir::LogicalResult emitOMPLoop(CIRGenFunction &cgf,
+                                       const OMPLoopDirective &s,
+                                       OperandsTy &clauseOps) {
   CIRGenBuilderTy &builder = cgf.getBuilder();
   CIRGenModule &cgm = cgf.getCIRGenModule();
   mlir::Location loc = cgf.getLoc(s.getBeginLoc());
 
-  if (mlir::failed(checkSynthesizedClauses(cgf, s, item)))
-    return mlir::failure();
-
-  mlir::omp::WsloopOperands clauseOps;
-  if (emitWsloopClauses(cgf, cgm, builder, loc, item->clauses, clauseOps)
-          .failed())
-    return mlir::failure();
-
   const CapturedStmt *capturedStmt = s.getInnermostCapturedStmt();
   const auto *forStmt = cast<ForStmt>(capturedStmt->getCapturedStmt());
 
@@ -502,13 +524,13 @@ emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
     tripCount = builder.createBuiltinIntCast(loc, tripCountCir);
   }
 
-  auto wsloopOp = mlir::omp::WsloopOp::create(builder, loc, clauseOps);
+  auto loopOp = OpTy::create(builder, loc, clauseOps);
   mlir::Block *innerBlock = new mlir::Block();
   // Ensures the block arguments match BlockArgOpenMPOpInterface's expected
   // order.
   for (auto &counterMold : counterMolds)
     innerBlock->addArgument(counterMold.second.getPointer().getType(), loc);
-  wsloopOp.getRegion().push_back(innerBlock);
+  loopOp.getRegion().push_back(innerBlock);
 
   mlir::OpBuilder::InsertionGuard guard(builder);
   builder.setInsertionPointToStart(innerBlock);
@@ -527,6 +549,58 @@ emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
                          s.updates()[0]);
 }
 
+/// Lowers an OMPLoopDirective's `for` directive to an omp.wsloop +
+/// omp.loop_nest.
+static mlir::LogicalResult
+emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
+                       omp::ConstructQueue::const_iterator item) {
+  if (mlir::failed(checkSynthesizedClauses(cgf, s, item)))
+    return mlir::failure();
+
+  mlir::omp::WsloopOperands clauseOps;
+  if (emitWsloopClauses(cgf, cgf.getCIRGenModule(), cgf.getBuilder(),
+                        cgf.getLoc(s.getBeginLoc()), item->clauses, clauseOps)
+          .failed())
+    return mlir::failure();
+
+  return emitOMPLoop<mlir::omp::WsloopOp>(cgf, s, clauseOps);
+}
+
+/// Evaluates the clauses allowed on the `distribute` directive; none are
+/// supported yet, so every eligible clause is reported as NYI.
+static mlir::LogicalResult
+emitDistributeClauses(CIRGenFunction &cgf, CIRGenModule &cgm,
+                      CIRGenBuilderTy &builder, mlir::Location loc,
+                      llvm::ArrayRef<const OMPClause *> clauses,
+                      mlir::omp::DistributeOperands &clauseOps) {
+  OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses);
+  return ce.emitNYI</*supported=*/>(
+      /*nyi=*/OpenMPNYIClauseList<OMPAllocateClause, OMPCollapseClause,
+                                  OMPDistScheduleClause, OMPFirstprivateClause,
+                                  OMPLastprivateClause, OMPOrderClause,
+                                  OMPPrivateClause>{},
+      llvm::omp::Directive::OMPD_distribute);
+}
+
+/// Lowers an OMPLoopDirective's `distribute` directive to an omp.distribute +
+/// omp.loop_nest, sharing the canonical loop lowering with the worksharing
+/// loop (see emitOMPLoop).
+static mlir::LogicalResult
+emitOMPDistributeLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
+                      omp::ConstructQueue::const_iterator item) {
+  if (mlir::failed(checkSynthesizedClauses(cgf, s, item)))
+    return mlir::failure();
+
+  mlir::omp::DistributeOperands clauseOps;
+  if (emitDistributeClauses(cgf, cgf.getCIRGenModule(), cgf.getBuilder(),
+                            cgf.getLoc(s.getBeginLoc()), item->clauses,
+                            clauseOps)
+          .failed())
+    return mlir::failure();
+
+  return emitOMPLoop<mlir::omp::DistributeOp>(cgf, s, clauseOps);
+}
+
 mlir::LogicalResult
 CIRGenFunction::emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s) {
   getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskwaitDirective");
@@ -764,9 +838,10 @@ emitTargetOp(CIRGenFunction &cgf, const DirectiveTy &s,
 
   const auto &execDir = static_cast<const OMPExecutableDirective &>(s);
   bool isSPMD = isTargetSPMD(execDir);
-
+  bool needsHostEvalTripCount = isSPMD || isTargetTeamsDistribute(execDir);
   std::optional<CIRGenFunction::OMPHostEvalBounds> hostEval;
-  if (isSPMD && !cgf.getCIRGenModule().getLangOpts().OpenMPIsTargetDevice) {
+  if (needsHostEvalTripCount &&
+      !cgf.getCIRGenModule().getLangOpts().OpenMPIsTargetDevice) {
     const auto *loopDir = dyn_cast<OMPLoopDirective>(&execDir);
     if (!loopDir)
       loopDir = findNestedOMPLoopDirective(execDir);
@@ -1043,9 +1118,9 @@ mlir::LogicalResult CIRGenFunction::emitOMPParallelMasterTaskLoopSimdDirective(
 }
 mlir::LogicalResult
 CIRGenFunction::emitOMPDistributeDirective(const OMPDistributeDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(),
-                             "OpenMP OMPDistributeDirective");
-  return mlir::failure();
+  omp::ConstructQueue queue =
+      omp::buildConstructQueue(getContext().getLangOpts().OpenMP, s);
+  return emitOMPDistributeLoop(*this, s, queue.begin());
 }
 mlir::LogicalResult CIRGenFunction::emitOMPDistributeParallelForDirective(
     const OMPDistributeParallelForDirective &s) {
@@ -1097,9 +1172,25 @@ mlir::LogicalResult CIRGenFunction::emitOMPTargetUpdateDirective(
 }
 mlir::LogicalResult CIRGenFunction::emitOMPTeamsDistributeDirective(
     const OMPTeamsDistributeDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(),
-                             "OpenMP OMPTeamsDistributeDirective");
-  return mlir::failure();
+  mlir::Location begin = getLoc(s.getBeginLoc());
+  mlir::Location end = getLoc(s.getEndLoc());
+
+  omp::ConstructQueue queue =
+      omp::buildConstructQueue(getContext().getLangOpts().OpenMP, s);
+  omp::ConstructQueue::const_iterator teamsItem = queue.begin();
+  assert(teamsItem->id == llvm::omp::OMPD_teams &&
+         "expected 'teams' to be the outermost directive");
+
+  return emitTeams(*this, s, queue, teamsItem, begin, end,
+                   [&]() -> mlir::LogicalResult {
+                     omp::ConstructQueue::const_iterator distributeItem =
+                         std::next(teamsItem);
+                     assert(distributeItem != queue.end() &&
+                            distributeItem->id == llvm::omp::OMPD_distribute &&
+                            "expected a 'distribute' directive nested in "
+                            "'teams'");
+                     return emitOMPDistributeLoop(*this, s, distributeItem);
+                   });
 }
 mlir::LogicalResult CIRGenFunction::emitOMPTeamsDistributeSimdDirective(
     const OMPTeamsDistributeSimdDirective &s) {
@@ -1155,9 +1246,33 @@ CIRGenFunction::emitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &s) {
 }
 mlir::LogicalResult CIRGenFunction::emitOMPTargetTeamsDistributeDirective(
     const OMPTargetTeamsDistributeDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(),
-                             "OpenMP OMPTargetTeamsDistributeDirective");
-  return mlir::failure();
+  mlir::Location begin = getLoc(s.getBeginLoc());
+  mlir::Location end = getLoc(s.getEndLoc());
+
+  omp::ConstructQueue queue =
+      omp::buildConstructQueue(getContext().getLangOpts().OpenMP, s);
+  omp::ConstructQueue::const_iterator targetItem = queue.begin();
+  assert(targetItem->id == llvm::omp::OMPD_target &&
+         "expected 'target' to be the outermost directive");
+
+  return emitTarget(
+      *this, s, queue, targetItem, begin, end, [&]() -> mlir::LogicalResult {
+        omp::ConstructQueue::const_iterator teamsItem = std::next(targetItem);
+        assert(teamsItem != queue.end() &&
+               teamsItem->id == llvm::omp::OMPD_teams &&
+               "expected a 'teams' directive nested in 'target'");
+
+        return emitTeams(
+            *this, s, queue, teamsItem, begin, end,
+            [&]() -> mlir::LogicalResult {
+              omp::ConstructQueue::const_iterator distributeItem =
+                  std::next(teamsItem);
+              assert(distributeItem != queue.end() &&
+                     distributeItem->id == llvm::omp::OMPD_distribute &&
+                     "expected a 'distribute' directive nested in 'teams'");
+              return emitOMPDistributeLoop(*this, s, distributeItem);
+            });
+      });
 }
 mlir::LogicalResult
 CIRGenFunction::emitOMPTargetTeamsDistributeParallelForDirective(
diff --git a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
index ef28330b2a478f..fd58fae5ea4ec0 100644
--- a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
+++ b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
@@ -39,4 +39,16 @@ void do_things() {
   // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP TEAMS 'thread_limit' clause}}
 #pragma omp teams thread_limit(8)
   {}
+
+  // The distribute construct supports no clauses yet, so every
+  // `distribute` clause is reported as not-yet-implemented.
+  // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP DISTRIBUTE 'dist_schedule' clause}}
+#pragma omp teams distribute dist_schedule(static)
+  for (int j = 0; j < 10; j++) {
+  }
+
+  // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP DISTRIBUTE 'collapse' clause}}
+#pragma omp teams distribute collapse(1)
+  for (int j = 0; j < 10; j++) {
+  }
 }
diff --git a/clang/test/CIR/CodeGenOpenMP/target-teams-distribute.c b/clang/test/CIR/CodeGenOpenMP/target-teams-distribute.c
new file mode 100644
index 00000000000000..c90ec124254e95
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/target-teams-distribute.c
@@ -0,0 +1,708 @@
+// REQUIRES: amdgpu-registered-target
+
+// Host compilation (x86 host, AMDGPU offload target).
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -emit-cir -fclangir %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CIR-HOST
+
+// Device compilation (AMDGPU): allocas live in the private address space.
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-target-device \
+// RUN:   -emit-cir -fclangir %s -o - \
+// RUN:   | FileCheck %s --check-prefix=CIR-DEVICE
+
+// Host-side lowering to LLVM IR: identical on both paths, so LLVM-HOST
+// checks both. The only difference is where the second function's helper
+// functions end up relative to the first function's, checked below under
+// LLVM-HOST-CIR/LLVM-HOST-OGCG.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp \
+// RUN:   -fopenmp-targets=amdgcn-amd-amdhsa -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM-HOST,LLVM-HOST-CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp \
+// RUN:   -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM-HOST,LLVM-HOST-OGCG
+
+// Device-side lowering to LLVM IR: compiled in two steps to mirror the
+// offloading driver.
+// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -fopenmp-targets=amdgcn-amd-amdhsa \
+// RUN:   -fclangir -emit-llvm-bc %s -o %t-cir-host.bc
+// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -fopenmp-targets=amdgcn-amd-amdhsa \
+// RUN:   -emit-llvm-bc %s -o %t-ogcg-host.bc
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-target-device \
+// RUN:   -fopenmp-host-ir-file-path %t-cir-host.bc \
+// RUN:   -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM-DEVICE,LLVM-DEVICE-CIR
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-is-target-device \
+// RUN:   -fopenmp-host-ir-file-path %t-ogcg-host.bc \
+// RUN:   -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM-DEVICE,LLVM-DEVICE-OGCG
+
+void during(int);
+
+// `target teams distribute` stays a generic (non-SPMD) kernel_type, but
+// still needs its trip count host_eval'd.
+void explicit_target_teams_distribute() {
+#pragma omp target
+  {
+#pragma omp teams
+    {
+#pragma omp distribute
+      for (int i = 0; i < 10; i++) {
+        during(i);
+      }
+    }
+  }
+}
+
+// CIR-HOST: cir.func{{.*}}@explicit_target_teams_distribute(
+// The host computes the trip count before the omp.target and passes it
+// in through host_eval.
+// tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+// CIR-HOST-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-HOST-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-HOST-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-HOST-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-HOST-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-HOST-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: omp.target kernel_type(generic) host_eval(%[[ZERO]] -> %[[AZERO:.*]], %[[TRIPCOUNT]] -> %[[ATRIPCOUNT:.*]], %[[ONE]] -> %[[AONE:.*]] : i32, i32, i32) {
+// CIR-HOST-NEXT:   omp.teams {
+// CIR-HOST-NEXT:     %[[IV_ADDR:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     omp.distribute private(@{{.*}} %[[I_ALLOCA]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-HOST-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[AZERO]]) to (%[[ATRIPCOUNT]]) step (%[[AONE]]) {
+// CIR-HOST-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-HOST-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.call @{{.*}}during
+// CIR-HOST:          omp.yield
+// CIR-HOST:        }
+// CIR-HOST:      }
+// CIR-HOST:      omp.terminator
+// CIR-HOST:    } {omp.combined}
+// CIR-HOST:    omp.terminator
+// CIR-HOST:  } {omp.combined}
+
+// CIR-DEVICE: cir.func{{.*}}@explicit_target_teams_distribute(
+// CIR-DEVICE-NEXT: omp.target kernel_type(generic) {
+// CIR-DEVICE-NEXT:   omp.teams {
+// CIR-DEVICE-NEXT:     %[[IV_ALLOCA:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ADDR:.*]] = cir.cast address_space %[[I_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// CIR-DEVICE-NEXT:     %[[IV_ADDR:.*]] = cir.cast address_space %[[IV_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// The device has no host_eval operands, so it recomputes the same trip count
+// inside the region.
+// CIR-DEVICE-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-DEVICE-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT:     omp.distribute private(@{{.*}} %[[I_ADDR]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-DEVICE-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[ZERO]]) to (%[[TRIPCOUNT]]) step (%[[ONE]]) {
+// CIR-DEVICE-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-DEVICE-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.call @{{.*}}during
+// CIR-DEVICE:          omp.yield
+// CIR-DEVICE:        }
+// CIR-DEVICE:      }
+// CIR-DEVICE:      omp.terminator
+// CIR-DEVICE:    } {omp.combined}
+// CIR-DEVICE:    omp.terminator
+// CIR-DEVICE:  } {omp.combined}
+
+// The combined `target teams distribute` form decomposes into the same
+// target/teams/distribute directive nesting as above, so it lowers
+// identically.
+void target_teams_distribute() {
+#pragma omp target teams distribute
+  for (int i = 0; i < 10; i++) {
+    during(i);
+  }
+}
+
+// CIR-HOST: cir.func{{.*}}@target_teams_distribute(
+// The host computes the trip count before the omp.target and passes it
+// in through host_eval.
+// tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+// CIR-HOST-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-HOST-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-HOST-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-HOST-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-HOST-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-HOST-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: omp.target kernel_type(generic) host_eval(%[[ZERO]] -> %[[AZERO:.*]], %[[TRIPCOUNT]] -> %[[ATRIPCOUNT:.*]], %[[ONE]] -> %[[AONE:.*]] : i32, i32, i32) {
+// CIR-HOST-NEXT:   omp.teams {
+// CIR-HOST-NEXT:     %[[IV_ADDR:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     omp.distribute private(@{{.*}} %[[I_ALLOCA]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-HOST-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[AZERO]]) to (%[[ATRIPCOUNT]]) step (%[[AONE]]) {
+// CIR-HOST-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-HOST-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.call @{{.*}}during
+// CIR-HOST:          omp.yield
+// CIR-HOST:        }
+// CIR-HOST:      }
+// CIR-HOST:      omp.terminator
+// CIR-HOST:    } {omp.combined}
+// CIR-HOST:    omp.terminator
+// CIR-HOST:  } {omp.combined}
+
+// CIR-DEVICE: cir.func{{.*}}@target_teams_distribute(
+// CIR-DEVICE-NEXT: omp.target kernel_type(generic) {
+// CIR-DEVICE-NEXT:   omp.teams {
+// CIR-DEVICE-NEXT:     %[[IV_ALLOCA:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ADDR:.*]] = cir.cast address_space %[[I_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// CIR-DEVICE-NEXT:     %[[IV_ADDR:.*]] = cir.cast address_space %[[IV_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// The device has no host_eval operands, so it recomputes the same trip count
+// inside the region.
+// CIR-DEVICE-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-DEVICE-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT:     omp.distribute private(@{{.*}} %[[I_ADDR]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-DEVICE-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[ZERO]]) to (%[[TRIPCOUNT]]) step (%[[ONE]]) {
+// CIR-DEVICE-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-DEVICE-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.call @{{.*}}during
+// CIR-DEVICE:          omp.yield
+// CIR-DEVICE:        }
+// CIR-DEVICE:      }
+// CIR-DEVICE:      omp.terminator
+// CIR-DEVICE:    } {omp.combined}
+// CIR-DEVICE:    omp.terminator
+// CIR-DEVICE:  } {omp.combined}
+
+void target_teams_split_distribute() {
+#pragma omp target teams
+#pragma omp distribute
+  for (int i = 0; i < 10; i++) {
+    during(i);
+  }
+}
+
+// CIR-HOST: cir.func{{.*}}@target_teams_split_distribute(
+// The host computes the trip count before the omp.target and passes it
+// in through host_eval.
+// tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+// CIR-HOST-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-HOST-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-HOST-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-HOST-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-HOST-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-HOST-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: omp.target kernel_type(generic) host_eval(%[[ZERO]] -> %[[AZERO:.*]], %[[TRIPCOUNT]] -> %[[ATRIPCOUNT:.*]], %[[ONE]] -> %[[AONE:.*]] : i32, i32, i32) {
+// CIR-HOST-NEXT:   omp.teams {
+// CIR-HOST-NEXT:     %[[IV_ADDR:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     omp.distribute private(@{{.*}} %[[I_ALLOCA]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-HOST-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[AZERO]]) to (%[[ATRIPCOUNT]]) step (%[[AONE]]) {
+// CIR-HOST-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-HOST-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.call @{{.*}}during
+// CIR-HOST:          omp.yield
+// CIR-HOST:        }
+// CIR-HOST:      }
+// CIR-HOST:      omp.terminator
+// CIR-HOST:    } {omp.combined}
+// CIR-HOST:    omp.terminator
+// CIR-HOST:  } {omp.combined}
+
+// CIR-DEVICE: cir.func{{.*}}@target_teams_split_distribute(
+// CIR-DEVICE-NEXT: omp.target kernel_type(generic) {
+// CIR-DEVICE-NEXT:   omp.teams {
+// CIR-DEVICE-NEXT:     %[[IV_ALLOCA:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ADDR:.*]] = cir.cast address_space %[[I_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// CIR-DEVICE-NEXT:     %[[IV_ADDR:.*]] = cir.cast address_space %[[IV_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// The device has no host_eval operands, so it recomputes the same trip count
+// inside the region.
+// CIR-DEVICE-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-DEVICE-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT:     omp.distribute private(@{{.*}} %[[I_ADDR]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-DEVICE-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[ZERO]]) to (%[[TRIPCOUNT]]) step (%[[ONE]]) {
+// CIR-DEVICE-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-DEVICE-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.call @{{.*}}during
+// CIR-DEVICE:          omp.yield
+// CIR-DEVICE:        }
+// CIR-DEVICE:      }
+// CIR-DEVICE:      omp.terminator
+// CIR-DEVICE:    } {omp.combined}
+// CIR-DEVICE:    omp.terminator
+// CIR-DEVICE:  } {omp.combined}
+
+// A split `target`, with a separately, explicitly nested but combined
+// `teams distribute`, is the fourth and final form: the other mix of
+// combined/split not yet covered above. Just like the other three
+// forms, its omp.target still needs its trip count host_eval'd, even
+// though the nested construct is now a single `teams_distribute` AST node
+// rather than two separate `teams`/`distribute` nodes.
+void target_split_teams_distribute() {
+#pragma omp target
+#pragma omp teams distribute
+  for (int i = 0; i < 10; i++) {
+    during(i);
+  }
+}
+
+// CIR-HOST: cir.func{{.*}}@target_split_teams_distribute(
+// The host computes the trip count before the omp.target and passes it
+// in through host_eval.
+// tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+// CIR-HOST-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-HOST-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-HOST-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-HOST-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-HOST-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-HOST-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-HOST-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-HOST-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-HOST-NEXT: omp.target kernel_type(generic) host_eval(%[[ZERO]] -> %[[AZERO:.*]], %[[TRIPCOUNT]] -> %[[ATRIPCOUNT:.*]], %[[ONE]] -> %[[AONE:.*]] : i32, i32, i32) {
+// CIR-HOST-NEXT:   omp.teams {
+// CIR-HOST-NEXT:     %[[IV_ADDR:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+// CIR-HOST-NEXT:     omp.distribute private(@{{.*}} %[[I_ALLOCA]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-HOST-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[AZERO]]) to (%[[ATRIPCOUNT]]) step (%[[AONE]]) {
+// CIR-HOST-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-HOST-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-HOST:          cir.call @{{.*}}during
+// CIR-HOST:          omp.yield
+// CIR-HOST:        }
+// CIR-HOST:      }
+// CIR-HOST:      omp.terminator
+// CIR-HOST:    } {omp.combined}
+// CIR-HOST:    omp.terminator
+// CIR-HOST:  } {omp.combined}
+
+// CIR-DEVICE: cir.func{{.*}}@target_split_teams_distribute(
+// CIR-DEVICE-NEXT: omp.target kernel_type(generic) {
+// CIR-DEVICE-NEXT:   omp.teams {
+// CIR-DEVICE-NEXT:     %[[IV_ALLOCA:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i, target_address_space(5)>
+// CIR-DEVICE-NEXT:     %[[I_ADDR:.*]] = cir.cast address_space %[[I_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// CIR-DEVICE-NEXT:     %[[IV_ADDR:.*]] = cir.cast address_space %[[IV_ALLOCA]] : !cir.ptr<!s32i, target_address_space(5)> -> !cir.ptr<!s32i>
+// The device has no host_eval operands, so it recomputes the same trip count
+// inside the region.
+// CIR-DEVICE-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+// CIR-DEVICE-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+// CIR-DEVICE-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+// CIR-DEVICE-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-DEVICE-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+// CIR-DEVICE-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+// CIR-DEVICE-NEXT:     omp.distribute private(@{{.*}} %[[I_ADDR]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+// CIR-DEVICE-NEXT:       omp.loop_nest (%[[IV:.*]]) : i32 = (%[[ZERO]]) to (%[[TRIPCOUNT]]) step (%[[ONE]]) {
+// CIR-DEVICE-NEXT:     %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+// CIR-DEVICE-NEXT:     cir.store align(4) %[[IV_CIR]], %[[IV_ADDR]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+// CIR-DEVICE:          cir.call @{{.*}}during
+// CIR-DEVICE:          omp.yield
+// CIR-DEVICE:        }
+// CIR-DEVICE:      }
+// CIR-DEVICE:      omp.terminator
+// CIR-DEVICE:    } {omp.combined}
+// CIR-DEVICE:    omp.terminator
+// CIR-DEVICE:  } {omp.combined}
+
+// Host wrappers: both paths store the trip count (10) in the kernel
+// arguments. CIR groups all its helper functions together after the host
+// wrappers, since the MLIR-to-LLVM translation emits them during the
+// lowering pass itself; OGCG's direct AST walk emits each one right after
+// its host wrapper. Only the host wrappers' positions differ, so the later
+// three are checked separately for each path.
+// LLVM-HOST-LABEL: define {{.*}} void @explicit_target_teams_distribute(
+// LLVM-HOST:         %[[KARGS:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST:         %[[TRIPCOUNT_GEP:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS]], i32 0, i32 8
+// LLVM-HOST-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP]], align 8
+// LLVM-HOST:         call i32 @__tgt_target_kernel(
+// LLVM-HOST:         br i1 %{{.*}}, label %[[FAILED:[^,]+]], label %{{.*}}
+// LLVM-HOST:       {{^}}[[FAILED]]:
+// LLVM-HOST-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_explicit_target_teams_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-CIR-LABEL: define {{.*}} void @target_teams_distribute(
+// LLVM-HOST-CIR:         %[[KARGS2:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-CIR:         %[[TRIPCOUNT_GEP2:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS2]], i32 0, i32 8
+// LLVM-HOST-CIR-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP2]], align 8
+// LLVM-HOST-CIR:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-CIR:         br i1 %{{.*}}, label %[[FAILED2:[^,]+]], label %{{.*}}
+// LLVM-HOST-CIR:       {{^}}[[FAILED2]]:
+// LLVM-HOST-CIR-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-CIR-LABEL: define {{.*}} void @target_teams_split_distribute(
+// LLVM-HOST-CIR:         %[[KARGS3:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-CIR:         %[[TRIPCOUNT_GEP3:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS3]], i32 0, i32 8
+// LLVM-HOST-CIR-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP3]], align 8
+// LLVM-HOST-CIR:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-CIR:         br i1 %{{.*}}, label %[[FAILED3:[^,]+]], label %{{.*}}
+// LLVM-HOST-CIR:       {{^}}[[FAILED3]]:
+// LLVM-HOST-CIR-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_split_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-CIR-LABEL: define {{.*}} void @target_split_teams_distribute(
+// LLVM-HOST-CIR:         %[[KARGS4:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-CIR:         %[[TRIPCOUNT_GEP4:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS4]], i32 0, i32 8
+// LLVM-HOST-CIR-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP4]], align 8
+// LLVM-HOST-CIR:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-CIR:         br i1 %{{.*}}, label %[[FAILED4:[^,]+]], label %{{.*}}
+// LLVM-HOST-CIR:       {{^}}[[FAILED4]]:
+// LLVM-HOST-CIR-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_split_teams_distribute_l{{[0-9]+}}(ptr null)
+
+// Outlined target-entry functions: fork the teams region via
+// __kmpc_fork_teams, same as the standalone `teams distribute` case in
+// teams-distribute.c. The forked function runs the distribute loop with
+// schedule 92 (static distribute); CIR and OGCG use a different runtime
+// API and control-flow shape for it.
+// LLVM-HOST-LABEL: define internal void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_explicit_target_teams_distribute_l{{[0-9]+}}(
+// LLVM-HOST:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED:[^)]+]])
+
+// LLVM-HOST-CIR:       define internal void @[[OUTLINED]](
+// LLVM-HOST-CIR:         store i32 0, ptr %[[LB:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 9, ptr %[[UB:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 1, ptr %[[STRIDE:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    %[[TID:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-HOST-CIR-SAME:      ptr {{.*}}, i32 %[[TID]], i32 92,
+// LLVM-HOST-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB]], ptr %[[UB]], ptr %[[STRIDE]],
+// LLVM-HOST-CIR-SAME:      i32 1, i32 0)
+// LLVM-HOST-CIR:         %[[IV:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT:[^,]+]], %{{.*}} ]
+// LLVM-HOST-CIR:         %[[LOOP_CMP:.*]] = icmp ult i32 %[[IV]], %{{.*}}
+// LLVM-HOST-CIR-NEXT:    br i1 %[[LOOP_CMP]], label %[[LOOP_BODY:[^,]+]], label %[[LOOP_EXIT:[^ ,]+]]
+// LLVM-HOST-CIR:       {{^}}[[LOOP_EXIT]]:
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID]])
+// LLVM-HOST-CIR:       {{^}}[[LOOP_BODY]]:
+// LLVM-HOST-CIR:         call void @during(i32
+// LLVM-HOST-CIR:         %[[NEXT]] = add nuw i32 %[[IV]], 1
+
+// LLVM-HOST-OGCG:       define internal void @[[OUTLINED]](
+// LLVM-HOST-OGCG:         store i32 0, ptr %[[OMP_LB:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST:.*]], align 4
+// LLVM-HOST-OGCG:         %[[TID_OGCG:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-HOST-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-HOST-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG]], i32 92,
+// LLVM-HOST-OGCG-SAME:      ptr %[[OMP_IS_LAST]], ptr %[[OMP_LB]], ptr %[[OMP_UB]], ptr %[[OMP_STRIDE]],
+// LLVM-HOST-OGCG-SAME:      i32 1, i32 1)
+// LLVM-HOST-OGCG:         call void @during(i32
+// LLVM-HOST-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG]])
+// LLVM-HOST-OGCG-NEXT:    ret void
+
+// LLVM-HOST-OGCG-LABEL: define {{.*}} void @target_teams_distribute(
+// LLVM-HOST-OGCG:         %[[KARGS2:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-OGCG:         %[[TRIPCOUNT_GEP2:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS2]], i32 0, i32 8
+// LLVM-HOST-OGCG-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP2]], align 8
+// LLVM-HOST-OGCG:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-OGCG:         br i1 %{{.*}}, label %[[FAILED2:[^,]+]], label %{{.*}}
+// LLVM-HOST-OGCG:       {{^}}[[FAILED2]]:
+// LLVM-HOST-OGCG-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-LABEL: define internal void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_distribute_l{{[0-9]+}}(
+// LLVM-HOST:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED2:[^)]+]])
+
+// LLVM-HOST-CIR:       define internal void @[[OUTLINED2]](
+// LLVM-HOST-CIR:         store i32 0, ptr %[[LB2:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 9, ptr %[[UB2:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 1, ptr %[[STRIDE2:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    %[[TID2:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-HOST-CIR-SAME:      ptr {{.*}}, i32 %[[TID2]], i32 92,
+// LLVM-HOST-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB2]], ptr %[[UB2]], ptr %[[STRIDE2]],
+// LLVM-HOST-CIR-SAME:      i32 1, i32 0)
+// LLVM-HOST-CIR:         %[[IV2:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT2:[^,]+]], %{{.*}} ]
+// LLVM-HOST-CIR:         %[[LOOP_CMP2:.*]] = icmp ult i32 %[[IV2]], %{{.*}}
+// LLVM-HOST-CIR-NEXT:    br i1 %[[LOOP_CMP2]], label %[[LOOP_BODY2:[^,]+]], label %[[LOOP_EXIT2:[^ ,]+]]
+// LLVM-HOST-CIR:       {{^}}[[LOOP_EXIT2]]:
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID2]])
+// LLVM-HOST-CIR:       {{^}}[[LOOP_BODY2]]:
+// LLVM-HOST-CIR:         call void @during(i32
+// LLVM-HOST-CIR:         %[[NEXT2]] = add nuw i32 %[[IV2]], 1
+
+// LLVM-HOST-OGCG:       define internal void @[[OUTLINED2]](
+// LLVM-HOST-OGCG:         store i32 0, ptr %[[OMP_LB2:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB2:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE2:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST2:.*]], align 4
+// LLVM-HOST-OGCG:         %[[TID_OGCG2:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-HOST-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-HOST-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG2]], i32 92,
+// LLVM-HOST-OGCG-SAME:      ptr %[[OMP_IS_LAST2]], ptr %[[OMP_LB2]], ptr %[[OMP_UB2]], ptr %[[OMP_STRIDE2]],
+// LLVM-HOST-OGCG-SAME:      i32 1, i32 1)
+// LLVM-HOST-OGCG:         call void @during(i32
+// LLVM-HOST-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG2]])
+// LLVM-HOST-OGCG-NEXT:    ret void
+
+// LLVM-HOST-OGCG-LABEL: define {{.*}} void @target_teams_split_distribute(
+// LLVM-HOST-OGCG:         %[[KARGS3:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-OGCG:         %[[TRIPCOUNT_GEP3:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS3]], i32 0, i32 8
+// LLVM-HOST-OGCG-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP3]], align 8
+// LLVM-HOST-OGCG:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-OGCG:         br i1 %{{.*}}, label %[[FAILED3:[^,]+]], label %{{.*}}
+// LLVM-HOST-OGCG:       {{^}}[[FAILED3]]:
+// LLVM-HOST-OGCG-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_split_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-LABEL: define internal void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_split_distribute_l{{[0-9]+}}(
+// LLVM-HOST:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED3:[^)]+]])
+
+// LLVM-HOST-CIR:       define internal void @[[OUTLINED3]](
+// LLVM-HOST-CIR:         store i32 0, ptr %[[LB3:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 9, ptr %[[UB3:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 1, ptr %[[STRIDE3:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    %[[TID3:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-HOST-CIR-SAME:      ptr {{.*}}, i32 %[[TID3]], i32 92,
+// LLVM-HOST-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB3]], ptr %[[UB3]], ptr %[[STRIDE3]],
+// LLVM-HOST-CIR-SAME:      i32 1, i32 0)
+// LLVM-HOST-CIR:         %[[IV3:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT3:[^,]+]], %{{.*}} ]
+// LLVM-HOST-CIR:         %[[LOOP_CMP3:.*]] = icmp ult i32 %[[IV3]], %{{.*}}
+// LLVM-HOST-CIR-NEXT:    br i1 %[[LOOP_CMP3]], label %[[LOOP_BODY3:[^,]+]], label %[[LOOP_EXIT3:[^ ,]+]]
+// LLVM-HOST-CIR:       {{^}}[[LOOP_EXIT3]]:
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID3]])
+// LLVM-HOST-CIR:       {{^}}[[LOOP_BODY3]]:
+// LLVM-HOST-CIR:         call void @during(i32
+// LLVM-HOST-CIR:         %[[NEXT3]] = add nuw i32 %[[IV3]], 1
+
+// LLVM-HOST-OGCG:       define internal void @[[OUTLINED3]](
+// LLVM-HOST-OGCG:         store i32 0, ptr %[[OMP_LB3:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB3:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE3:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST3:.*]], align 4
+// LLVM-HOST-OGCG:         %[[TID_OGCG3:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-HOST-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-HOST-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG3]], i32 92,
+// LLVM-HOST-OGCG-SAME:      ptr %[[OMP_IS_LAST3]], ptr %[[OMP_LB3]], ptr %[[OMP_UB3]], ptr %[[OMP_STRIDE3]],
+// LLVM-HOST-OGCG-SAME:      i32 1, i32 1)
+// LLVM-HOST-OGCG:         call void @during(i32
+// LLVM-HOST-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG3]])
+// LLVM-HOST-OGCG-NEXT:    ret void
+
+// LLVM-HOST-OGCG-LABEL: define {{.*}} void @target_split_teams_distribute(
+// LLVM-HOST-OGCG:         %[[KARGS4:.*]] = alloca %struct.__tgt_kernel_arguments, align 8
+// LLVM-HOST-OGCG:         %[[TRIPCOUNT_GEP4:.*]] = getelementptr inbounds nuw %struct.__tgt_kernel_arguments, ptr %[[KARGS4]], i32 0, i32 8
+// LLVM-HOST-OGCG-NEXT:    store i64 10, ptr %[[TRIPCOUNT_GEP4]], align 8
+// LLVM-HOST-OGCG:         call i32 @__tgt_target_kernel(
+// LLVM-HOST-OGCG:         br i1 %{{.*}}, label %[[FAILED4:[^,]+]], label %{{.*}}
+// LLVM-HOST-OGCG:       {{^}}[[FAILED4]]:
+// LLVM-HOST-OGCG-NEXT:    call void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_split_teams_distribute_l{{[0-9]+}}(ptr null)
+
+// LLVM-HOST-LABEL: define internal void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_split_teams_distribute_l{{[0-9]+}}(
+// LLVM-HOST:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED4:[^)]+]])
+
+// LLVM-HOST-CIR:       define internal void @[[OUTLINED4]](
+// LLVM-HOST-CIR:         store i32 0, ptr %[[LB4:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 9, ptr %[[UB4:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    store i32 1, ptr %[[STRIDE4:.*]], align 4
+// LLVM-HOST-CIR-NEXT:    %[[TID4:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-HOST-CIR-SAME:      ptr {{.*}}, i32 %[[TID4]], i32 92,
+// LLVM-HOST-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB4]], ptr %[[UB4]], ptr %[[STRIDE4]],
+// LLVM-HOST-CIR-SAME:      i32 1, i32 0)
+// LLVM-HOST-CIR:         %[[IV4:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT4:[^,]+]], %{{.*}} ]
+// LLVM-HOST-CIR:         %[[LOOP_CMP4:.*]] = icmp ult i32 %[[IV4]], %{{.*}}
+// LLVM-HOST-CIR-NEXT:    br i1 %[[LOOP_CMP4]], label %[[LOOP_BODY4:[^,]+]], label %[[LOOP_EXIT4:[^ ,]+]]
+// LLVM-HOST-CIR:       {{^}}[[LOOP_EXIT4]]:
+// LLVM-HOST-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID4]])
+// LLVM-HOST-CIR:       {{^}}[[LOOP_BODY4]]:
+// LLVM-HOST-CIR:         call void @during(i32
+// LLVM-HOST-CIR:         %[[NEXT4]] = add nuw i32 %[[IV4]], 1
+
+// LLVM-HOST-OGCG:       define internal void @[[OUTLINED4]](
+// LLVM-HOST-OGCG:         store i32 0, ptr %[[OMP_LB4:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB4:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE4:.*]], align 4
+// LLVM-HOST-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST4:.*]], align 4
+// LLVM-HOST-OGCG:         %[[TID_OGCG4:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-HOST-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-HOST-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG4]], i32 92,
+// LLVM-HOST-OGCG-SAME:      ptr %[[OMP_IS_LAST4]], ptr %[[OMP_LB4]], ptr %[[OMP_UB4]], ptr %[[OMP_STRIDE4]],
+// LLVM-HOST-OGCG-SAME:      i32 1, i32 1)
+// LLVM-HOST-OGCG:         call void @during(i32
+// LLVM-HOST-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG4]])
+// LLVM-HOST-OGCG-NEXT:    ret void
+
+// Device kernel entry: __kmpc_target_init/__kmpc_target_deinit and the
+// branch into the user code are identical on both paths.
+//
+// CIR's device-side `distribute` lowering uses the loop-callback-based
+// __kmpc_distribute_static_loop_4u API, which takes the trip count and needs
+// an extra level of outlining for the per-iteration callback (teams ->
+// distribute -> loop body); OGCG's distribute lowering uses the same direct
+// init/fini API as on the host, needing only one level of outlining (teams
+// -> loop body).
+// LLVM-DEVICE-LABEL: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_explicit_target_teams_distribute_l{{[0-9]+}}(
+// LLVM-DEVICE:         call i32 @__kmpc_target_init(
+// LLVM-DEVICE:         br i1 %{{.*}}, label %[[USER_CODE:[^,]+]], label %{{.*}}
+// LLVM-DEVICE:       {{^}}[[USER_CODE]]:
+// LLVM-DEVICE:         call void @[[DEV_TEAMS:__omp_offloading_[^(]+]](
+// LLVM-DEVICE:         call void @__kmpc_target_deinit()
+// LLVM-DEVICE-NEXT:    ret void
+
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_TEAMS]](
+// LLVM-DEVICE-CIR:         call void @[[DEV_DIST:__omp_offloading_[^(]+]](
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_DIST]](
+// LLVM-DEVICE-CIR:         call void @__kmpc_distribute_static_loop_4u(ptr {{.*}}, ptr @[[DEV_BODY:[^,]+]], ptr {{.*}}, i32 10, i32 0, i8 0)
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_BODY]](
+// LLVM-DEVICE-CIR:         call void @during(i32
+
+// LLVM-DEVICE-OGCG:       define internal void @[[DEV_TEAMS]](
+// LLVM-DEVICE-OGCG:         store i32 0, ptr %[[DEV_LB:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 9, ptr %[[DEV_UB:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 1, ptr %[[DEV_STRIDE:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 0, ptr %[[DEV_IS_LAST:.*]], align 4
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_init_4(
+// LLVM-DEVICE-OGCG-SAME:      ptr {{.*}}, i32 %{{.*}}, i32 92,
+// LLVM-DEVICE-OGCG-SAME:      ptr %[[DEV_IS_LAST]], ptr %[[DEV_LB]], ptr %[[DEV_UB]], ptr %[[DEV_STRIDE]],
+// LLVM-DEVICE-OGCG-SAME:      i32 1, i32 1)
+// LLVM-DEVICE-OGCG:         call void @during(i32
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_fini(
+
+// LLVM-DEVICE-LABEL: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_distribute_l{{[0-9]+}}(
+// LLVM-DEVICE:         call i32 @__kmpc_target_init(
+// LLVM-DEVICE:         br i1 %{{.*}}, label %[[USER_CODE2:[^,]+]], label %{{.*}}
+// LLVM-DEVICE:       {{^}}[[USER_CODE2]]:
+// LLVM-DEVICE:         call void @[[DEV_TEAMS2:__omp_offloading_[^(]+]](
+// LLVM-DEVICE:         call void @__kmpc_target_deinit()
+// LLVM-DEVICE-NEXT:    ret void
+
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_TEAMS2]](
+// LLVM-DEVICE-CIR:         call void @[[DEV_DIST2:__omp_offloading_[^(]+]](
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_DIST2]](
+// LLVM-DEVICE-CIR:         call void @__kmpc_distribute_static_loop_4u(ptr {{.*}}, ptr @[[DEV_BODY2:[^,]+]], ptr {{.*}}, i32 10, i32 0, i8 0)
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_BODY2]](
+// LLVM-DEVICE-CIR:         call void @during(i32
+
+// LLVM-DEVICE-OGCG:       define internal void @[[DEV_TEAMS2]](
+// LLVM-DEVICE-OGCG:         store i32 0, ptr %[[DEV_LB2:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 9, ptr %[[DEV_UB2:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 1, ptr %[[DEV_STRIDE2:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 0, ptr %[[DEV_IS_LAST2:.*]], align 4
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_init_4(
+// LLVM-DEVICE-OGCG-SAME:      ptr {{.*}}, i32 %{{.*}}, i32 92,
+// LLVM-DEVICE-OGCG-SAME:      ptr %[[DEV_IS_LAST2]], ptr %[[DEV_LB2]], ptr %[[DEV_UB2]], ptr %[[DEV_STRIDE2]],
+// LLVM-DEVICE-OGCG-SAME:      i32 1, i32 1)
+// LLVM-DEVICE-OGCG:         call void @during(i32
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_fini(
+
+// LLVM-DEVICE-LABEL: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_teams_split_distribute_l{{[0-9]+}}(
+// LLVM-DEVICE:         call i32 @__kmpc_target_init(
+// LLVM-DEVICE:         br i1 %{{.*}}, label %[[USER_CODE3:[^,]+]], label %{{.*}}
+// LLVM-DEVICE:       {{^}}[[USER_CODE3]]:
+// LLVM-DEVICE:         call void @[[DEV_TEAMS3:__omp_offloading_[^(]+]](
+// LLVM-DEVICE:         call void @__kmpc_target_deinit()
+// LLVM-DEVICE-NEXT:    ret void
+
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_TEAMS3]](
+// LLVM-DEVICE-CIR:         call void @[[DEV_DIST3:__omp_offloading_[^(]+]](
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_DIST3]](
+// LLVM-DEVICE-CIR:         call void @__kmpc_distribute_static_loop_4u(ptr {{.*}}, ptr @[[DEV_BODY3:[^,]+]], ptr {{.*}}, i32 10, i32 0, i8 0)
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_BODY3]](
+// LLVM-DEVICE-CIR:         call void @during(i32
+
+// LLVM-DEVICE-OGCG:       define internal void @[[DEV_TEAMS3]](
+// LLVM-DEVICE-OGCG:         store i32 0, ptr %[[DEV_LB3:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 9, ptr %[[DEV_UB3:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 1, ptr %[[DEV_STRIDE3:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 0, ptr %[[DEV_IS_LAST3:.*]], align 4
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_init_4(
+// LLVM-DEVICE-OGCG-SAME:      ptr {{.*}}, i32 %{{.*}}, i32 92,
+// LLVM-DEVICE-OGCG-SAME:      ptr %[[DEV_IS_LAST3]], ptr %[[DEV_LB3]], ptr %[[DEV_UB3]], ptr %[[DEV_STRIDE3]],
+// LLVM-DEVICE-OGCG-SAME:      i32 1, i32 1)
+// LLVM-DEVICE-OGCG:         call void @during(i32
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_fini(
+
+// LLVM-DEVICE-LABEL: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{[0-9a-f]+_[0-9a-f]+}}_target_split_teams_distribute_l{{[0-9]+}}(
+// LLVM-DEVICE:         call i32 @__kmpc_target_init(
+// LLVM-DEVICE:         br i1 %{{.*}}, label %[[USER_CODE4:[^,]+]], label %{{.*}}
+// LLVM-DEVICE:       {{^}}[[USER_CODE4]]:
+// LLVM-DEVICE:         call void @[[DEV_TEAMS4:__omp_offloading_[^(]+]](
+// LLVM-DEVICE:         call void @__kmpc_target_deinit()
+// LLVM-DEVICE-NEXT:    ret void
+
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_TEAMS4]](
+// LLVM-DEVICE-CIR:         call void @[[DEV_DIST4:__omp_offloading_[^(]+]](
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_DIST4]](
+// LLVM-DEVICE-CIR:         call void @__kmpc_distribute_static_loop_4u(ptr {{.*}}, ptr @[[DEV_BODY4:[^,]+]], ptr {{.*}}, i32 10, i32 0, i8 0)
+// LLVM-DEVICE-CIR:       define internal void @[[DEV_BODY4]](
+// LLVM-DEVICE-CIR:         call void @during(i32
+
+// LLVM-DEVICE-OGCG:       define internal void @[[DEV_TEAMS4]](
+// LLVM-DEVICE-OGCG:         store i32 0, ptr %[[DEV_LB4:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 9, ptr %[[DEV_UB4:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 1, ptr %[[DEV_STRIDE4:.*]], align 4
+// LLVM-DEVICE-OGCG-NEXT:    store i32 0, ptr %[[DEV_IS_LAST4:.*]], align 4
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_init_4(
+// LLVM-DEVICE-OGCG-SAME:      ptr {{.*}}, i32 %{{.*}}, i32 92,
+// LLVM-DEVICE-OGCG-SAME:      ptr %[[DEV_IS_LAST4]], ptr %[[DEV_LB4]], ptr %[[DEV_UB4]], ptr %[[DEV_STRIDE4]],
+// LLVM-DEVICE-OGCG-SAME:      i32 1, i32 1)
+// LLVM-DEVICE-OGCG:         call void @during(i32
+// LLVM-DEVICE-OGCG:         call void @__kmpc_distribute_static_fini(
diff --git a/clang/test/CIR/CodeGenOpenMP/teams-distribute.c b/clang/test/CIR/CodeGenOpenMP/teams-distribute.c
new file mode 100644
index 00000000000000..18214da6b6b51a
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/teams-distribute.c
@@ -0,0 +1,191 @@
+// RUN: %clang_cc1 -fopenmp -emit-cir -fclangir %s -o - | FileCheck %s --check-prefix=CIR
+
+// Lowering to LLVM IR: mostly identical between CIR and OGCG; they just name
+// the outlined functions differently.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM,LLVM-CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -emit-llvm %s -o - \
+// RUN:   | FileCheck %s --check-prefixes=LLVM,LLVM-OGCG
+
+void during(int);
+
+// Explicit `teams` + `distribute` nesting lowers the same as the combined
+// `teams distribute` spelling below, so both get omp.combined.
+void explicit_teams_distribute() {
+  // CIR: cir.func{{.*}}@explicit_teams_distribute
+#pragma omp teams
+  {
+#pragma omp distribute
+    for (int i = 0; i < 10; i++) {
+      during(i);
+    }
+  }
+
+  // CIR: omp.teams {
+  // CIR-NEXT: %[[IV_ALLOCA:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+  // CIR-NEXT: %[[I_ALLOCA:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+
+  // tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+  // CIR-NEXT: %[[HI:.*]] = cir.const #cir.int<10> : !s32i
+  // CIR-NEXT: %[[LO:.*]] = cir.const #cir.int<0> : !s32i
+  // CIR-NEXT: %[[STEP_A:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[LO_MINUS_STEP:.*]] = cir.sub nsw %[[LO]], %[[STEP_A]] : !s32i
+  // CIR-NEXT: %[[ONE_A:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[ADJ_LO:.*]] = cir.add nsw %[[LO_MINUS_STEP]], %[[ONE_A]] : !s32i
+  // CIR-NEXT: %[[SPAN:.*]] = cir.sub nsw %[[HI]], %[[ADJ_LO]] : !s32i
+  // CIR-NEXT: %[[STEP_B:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[TRIPCOUNT_CIR:.*]] = cir.div %[[SPAN]], %[[STEP_B]] : !s32i
+  // CIR-NEXT: %[[ZERO_CIR:.*]] = cir.const #cir.int<0> : !s32i
+  // CIR-NEXT: %[[ZERO:.*]] = cir.builtin_int_cast %[[ZERO_CIR]] : !s32i -> i32
+  // CIR-NEXT: %[[ONE_CIR:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[ONE:.*]] = cir.builtin_int_cast %[[ONE_CIR]] : !s32i -> i32
+  // CIR-NEXT: %[[TRIPCOUNT:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR]] : !s32i -> i32
+
+  // CIR-NEXT: omp.distribute private(@{{.*}} %[[I_ALLOCA]] -> %[[I_PRIV:.*]] : !cir.ptr<!s32i>) {
+  // CIR-NEXT: omp.loop_nest (%[[IV:.*]]) : i32 = (%[[ZERO]]) to (%[[TRIPCOUNT]]) step (%[[ONE]]) {
+  // CIR-NEXT: %[[IV_CIR:.*]] = cir.builtin_int_cast %[[IV]] : i32 -> !s32i
+  // CIR-NEXT: cir.store align(4) %[[IV_CIR]], %[[IV_ALLOCA]] : !s32i, !cir.ptr<!s32i>
+  // CIR: cir.store align(4) %{{.*}}, %[[I_PRIV]] : !s32i, !cir.ptr<!s32i>
+  // CIR: cir.load align(4) %[[I_PRIV]]
+  // CIR: cir.call @{{.*}}during
+  // CIR: omp.yield
+  // CIR: }
+  // CIR: }
+  // CIR: omp.terminator
+  // CIR: } {omp.combined}
+}
+
+// Combined `teams distribute` lowers the same as the explicit nesting
+// above, with omp.combined on the omp.teams.
+void teams_distribute() {
+  // CIR: cir.func{{.*}}@teams_distribute
+#pragma omp teams distribute
+  for (int i = 0; i < 10; i++) {
+    during(i);
+  }
+
+  // CIR: omp.teams {
+  // CIR-NEXT: %[[IV_ALLOCA2:.*]] = cir.alloca ".omp.iv" align(4) : !cir.ptr<!s32i>
+  // CIR-NEXT: %[[I_ALLOCA2:.*]] = cir.alloca "i" align(4) : !cir.ptr<!s32i>
+
+  // tripCount = (10 - (0 - 1 + 1)) / 1 = 10
+  // CIR-NEXT: %[[HI2:.*]] = cir.const #cir.int<10> : !s32i
+  // CIR-NEXT: %[[LO2:.*]] = cir.const #cir.int<0> : !s32i
+  // CIR-NEXT: %[[STEP_A2:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[LO_MINUS_STEP2:.*]] = cir.sub nsw %[[LO2]], %[[STEP_A2]] : !s32i
+  // CIR-NEXT: %[[ONE_A2:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[ADJ_LO2:.*]] = cir.add nsw %[[LO_MINUS_STEP2]], %[[ONE_A2]] : !s32i
+  // CIR-NEXT: %[[SPAN2:.*]] = cir.sub nsw %[[HI2]], %[[ADJ_LO2]] : !s32i
+  // CIR-NEXT: %[[STEP_B2:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[TRIPCOUNT_CIR2:.*]] = cir.div %[[SPAN2]], %[[STEP_B2]] : !s32i
+  // CIR-NEXT: %[[ZERO_CIR2:.*]] = cir.const #cir.int<0> : !s32i
+  // CIR-NEXT: %[[ZERO2:.*]] = cir.builtin_int_cast %[[ZERO_CIR2]] : !s32i -> i32
+  // CIR-NEXT: %[[ONE_CIR2:.*]] = cir.const #cir.int<1> : !s32i
+  // CIR-NEXT: %[[ONE2:.*]] = cir.builtin_int_cast %[[ONE_CIR2]] : !s32i -> i32
+  // CIR-NEXT: %[[TRIPCOUNT2:.*]] = cir.builtin_int_cast %[[TRIPCOUNT_CIR2]] : !s32i -> i32
+
+  // CIR-NEXT: omp.distribute private(@{{.*}} %[[I_ALLOCA2]] -> %[[I_PRIV2:.*]] : !cir.ptr<!s32i>) {
+  // CIR-NEXT: omp.loop_nest (%[[IV2:.*]]) : i32 = (%[[ZERO2]]) to (%[[TRIPCOUNT2]]) step (%[[ONE2]]) {
+  // CIR-NEXT: %[[IV_CIR2:.*]] = cir.builtin_int_cast %[[IV2]] : i32 -> !s32i
+  // CIR-NEXT: cir.store align(4) %[[IV_CIR2]], %[[IV_ALLOCA2]] : !s32i, !cir.ptr<!s32i>
+  // CIR: cir.store align(4) %{{.*}}, %[[I_PRIV2]] : !s32i, !cir.ptr<!s32i>
+  // CIR: cir.load align(4) %[[I_PRIV2]]
+  // CIR: cir.call @{{.*}}during
+  // CIR: omp.yield
+  // CIR: }
+  // CIR: }
+  // CIR: omp.terminator
+  // CIR: } {omp.combined}
+}
+
+// Host wrapper: __kmpc_fork_teams is identical on both paths. The
+// distribute loop inside the teams-outlined function uses schedule 92
+// (static distribute) with a different runtime API and control-flow shape
+// on each path.
+//
+// LLVM-LABEL: define {{.*}} void @explicit_teams_distribute(
+// LLVM:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED:[^)]+]])
+
+// LLVM-CIR:       define internal void @[[OUTLINED]](
+// LLVM-CIR:         store i32 0, ptr %[[LB:.*]], align 4
+// LLVM-CIR-NEXT:    store i32 9, ptr %[[UB:.*]], align 4
+// LLVM-CIR-NEXT:    store i32 1, ptr %[[STRIDE:.*]], align 4
+// LLVM-CIR-NEXT:    %[[TID:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-CIR-SAME:      ptr {{.*}}, i32 %[[TID]], i32 92,
+// LLVM-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB]], ptr %[[UB]], ptr %[[STRIDE]],
+// LLVM-CIR-SAME:      i32 1, i32 0)
+// LLVM-CIR:         %[[IV:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT:[^,]+]], %{{.*}} ]
+// LLVM-CIR:         %[[LOOP_CMP:.*]] = icmp ult i32 %[[IV]], %{{.*}}
+// LLVM-CIR-NEXT:    br i1 %[[LOOP_CMP]], label %[[LOOP_BODY:[^,]+]], label %[[LOOP_EXIT:[^ ,]+]]
+// LLVM-CIR:       {{^}}[[LOOP_EXIT]]:
+// LLVM-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID]])
+// LLVM-CIR:       {{^}}[[LOOP_BODY]]:
+// LLVM-CIR:         call void @during(i32
+// LLVM-CIR:         %[[NEXT]] = add nuw i32 %[[IV]], 1
+
+// LLVM-OGCG:       define internal void @[[OUTLINED]](
+// LLVM-OGCG:         store i32 0, ptr %[[OMP_LB:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST:.*]], align 4
+// LLVM-OGCG:         %[[TID_OGCG:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG]], i32 92,
+// LLVM-OGCG-SAME:      ptr %[[OMP_IS_LAST]], ptr %[[OMP_LB]], ptr %[[OMP_UB]], ptr %[[OMP_STRIDE]],
+// LLVM-OGCG-SAME:      i32 1, i32 1)
+// LLVM-OGCG:         %[[UB_VAL:.*]] = load i32, ptr %[[OMP_UB]], align 4
+// LLVM-OGCG-NEXT:    %[[CMP:.*]] = icmp sgt i32 %[[UB_VAL]], 9
+// LLVM-OGCG-NEXT:    br i1 %[[CMP]], label %[[COND_TRUE:[^,]+]], label %[[COND_FALSE:[^ ,]+]]
+// LLVM-OGCG:         %[[COND:.*]] = phi i32 [ 9, %[[COND_TRUE]] ], [ %{{.*}}, %[[COND_FALSE]] ]
+// LLVM-OGCG-NEXT:    store i32 %[[COND]], ptr %[[OMP_UB]], align 4
+// LLVM-OGCG:         %[[CMP1:.*]] = icmp sle i32 %{{.*}}, %{{.*}}
+// LLVM-OGCG-NEXT:    br i1 %[[CMP1]], label %[[FOR_BODY:[^,]+]], label %{{.*}}
+// LLVM-OGCG:       {{^}}[[FOR_BODY]]:
+// LLVM-OGCG:         call void @during(i32
+// LLVM-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG]])
+// LLVM-OGCG-NEXT:    ret void
+
+// `teams_distribute`
+// LLVM-LABEL: define {{.*}} void @teams_distribute(
+// LLVM:         call void (ptr, i32, ptr, ...) @__kmpc_fork_teams(ptr {{.*}}, i32 0, ptr @[[OUTLINED2:[^)]+]])
+
+// LLVM-CIR:       define internal void @[[OUTLINED2]](
+// LLVM-CIR:         store i32 0, ptr %[[LB2:.*]], align 4
+// LLVM-CIR-NEXT:    store i32 9, ptr %[[UB2:.*]], align 4
+// LLVM-CIR-NEXT:    store i32 1, ptr %[[STRIDE2:.*]], align 4
+// LLVM-CIR-NEXT:    %[[TID2:.*]] = call i32 @__kmpc_global_thread_num(ptr {{.*}})
+// LLVM-CIR-NEXT:    call void @__kmpc_for_static_init_4u(
+// LLVM-CIR-SAME:      ptr {{.*}}, i32 %[[TID2]], i32 92,
+// LLVM-CIR-SAME:      ptr %{{[^,]+}}, ptr %[[LB2]], ptr %[[UB2]], ptr %[[STRIDE2]],
+// LLVM-CIR-SAME:      i32 1, i32 0)
+// LLVM-CIR:         %[[IV2:.*]] = phi i32 [ 0, %{{.*}} ], [ %[[NEXT2:[^,]+]], %{{.*}} ]
+// LLVM-CIR:         %[[LOOP_CMP2:.*]] = icmp ult i32 %[[IV2]], %{{.*}}
+// LLVM-CIR-NEXT:    br i1 %[[LOOP_CMP2]], label %[[LOOP_BODY2:[^,]+]], label %[[LOOP_EXIT2:[^ ,]+]]
+// LLVM-CIR:       {{^}}[[LOOP_EXIT2]]:
+// LLVM-CIR-NEXT:    call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID2]])
+// LLVM-CIR:       {{^}}[[LOOP_BODY2]]:
+// LLVM-CIR:         call void @during(i32
+// LLVM-CIR:         %[[NEXT2]] = add nuw i32 %[[IV2]], 1
+
+// LLVM-OGCG:       define internal void @[[OUTLINED2]](
+// LLVM-OGCG:         store i32 0, ptr %[[OMP_LB2:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 9, ptr %[[OMP_UB2:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 1, ptr %[[OMP_STRIDE2:.*]], align 4
+// LLVM-OGCG-NEXT:    store i32 0, ptr %[[OMP_IS_LAST2:.*]], align 4
+// LLVM-OGCG:         %[[TID_OGCG2:.*]] = load i32, ptr %{{.*}}, align 4
+// LLVM-OGCG-NEXT:    call void @__kmpc_for_static_init_4(
+// LLVM-OGCG-SAME:      ptr {{.*}}, i32 %[[TID_OGCG2]], i32 92,
+// LLVM-OGCG-SAME:      ptr %[[OMP_IS_LAST2]], ptr %[[OMP_LB2]], ptr %[[OMP_UB2]], ptr %[[OMP_STRIDE2]],
+// LLVM-OGCG-SAME:      i32 1, i32 1)
+// LLVM-OGCG:         %[[UB_VAL2:.*]] = load i32, ptr %[[OMP_UB2]], align 4
+// LLVM-OGCG-NEXT:    %[[CMP2:.*]] = icmp sgt i32 %[[UB_VAL2]], 9
+// LLVM-OGCG-NEXT:    br i1 %[[CMP2]], label %[[COND_TRUE2:[^,]+]], label %[[COND_FALSE2:[^ ,]+]]
+// LLVM-OGCG:         %[[COND2:.*]] = phi i32 [ 9, %[[COND_TRUE2]] ], [ %{{.*}}, %[[COND_FALSE2]] ]
+// LLVM-OGCG-NEXT:    store i32 %[[COND2]], ptr %[[OMP_UB2]], align 4
+// LLVM-OGCG:         %[[CMP12:.*]] = icmp sle i32 %{{.*}}, %{{.*}}
+// LLVM-OGCG-NEXT:    br i1 %[[CMP12]], label %[[FOR_BODY2:[^,]+]], label %{{.*}}
+// LLVM-OGCG:       {{^}}[[FOR_BODY2]]:
+// LLVM-OGCG:         call void @during(i32
+// LLVM-OGCG:         call void @__kmpc_for_static_fini(ptr {{.*}}, i32 %[[TID_OGCG2]])
+// LLVM-OGCG-NEXT:    ret void



More information about the llvm-branch-commits mailing list