← Back to Pull requests

[clang][OpenMP] Emit lastprivate final copies in no-loop kernels #224045

Merged
nicebert merged 4 files (193 lines) on Dec 03, 2026 17:33 UTC
View on GitHub
nicebert nicebert commented on Sep 16, 2026 15:05 UTC
Author

Promotion rejected lastprivate because the no-loop branch leaves the
worksharing path before it privatizes or copies out, so the clause would
have been silently dropped.

Privatize the non-counter variables in the parallel region and copy them
out under the last iteration that applyWorkshareLoop publishes. Loop
counters stay at the distribute level and reach EmitOMPSimdFinal.

Split out of #205325.

Depends on: llvm/llvm-project#224040
Assisted by: Claude Opus 5.5

Diff: 193 lines (+168 / -25) across 4 files Reviewer: dhruvachak Review duration: 112468m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.44) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.44 · 193 lines diff across 4 files
0.44
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.84 · 5 substantive comment(s)
0.84
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.315
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
13 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Sep 16, 2026 15:05 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-offload

@llvm/pr-subscribers-clang-codegen

Author: Nicole Aschenbrenner (nicebert)

<details>
<summary>Changes</summary>

Promotion rejected lastprivate because the no-loop branch leaves the
worksharing path before it privatizes or copies out, so the clause would
have been silently dropped.

Privatize the non-counter variables in the parallel region and copy them
out under the last iteration that applyWorkshareLoop publishes, forcing
the exit barrier the copy reads through. Loop counters stay at the
distribute level and reach EmitOMPSimdFinal.

Split out of #<!-- -->205325.

Depends on: llvm/llvm-project#<!-- -->224040

---
Full diff: https://github.com/llvm/llvm-project/pull/224045.diff

4 Files Affected:

  • (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+1-3)

  • (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+60-8)

  • (modified) clang/test/OpenMP/target_no_loop.c (+54-1)

  • (modified) offload/test/offloading/target-no-loop.c (+48)
  • ``````

    diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
    index 264d78b0f5245..a22ccfcf3ddc2 100644
    --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
    +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
    @@ -1158,9 +1158,7 @@ bool CGOpenMPRuntimeGPU::canPromoteToNoLoop(
               DKind == OMPD_target_teams_distribute_parallel_for_simd) &&
              LangOpts.OpenMPTeamSubscription && LangOpts.OpenMPThreadSubscription &&
              !D.hasClausesOfKind<OMPNumTeamsClause>() &&
    -         !D.hasClausesOfKind<OMPReductionClause>() &&
    -         !D.hasClausesOfKind<OMPLastprivateClause>() &&
    -         !D.hasClausesOfKind<OMPLinearClause>();
    +         !D.hasClausesOfKind<OMPReductionClause>();
     }
     
     std::pair<llvm::Value *, llvm::Value *>
    diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
    index 4d19fa91172a8..4c59c726c66ff 100644
    --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
    +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
    @@ -66,6 +66,29 @@ static bool canEmitGPUFusedDistSchedule(const CodeGenModule &CGM,
              !S.getSingleClause<OMPOrderedClause>();
     }
     
    +static bool isLoopCounter(const OMPLoopDirective &S, const Expr *E) {
    +  const VarDecl *Canonical =
    +      cast<VarDecl>(cast<DeclRefExpr>(E->IgnoreParenImpCasts())->getDecl())
    +          ->getCanonicalDecl();
    +  for (const Expr *C : S.counters())
    +    if (cast<VarDecl>(cast<DeclRefExpr>(C)->getDecl())->getCanonicalDecl() ==
    +        Canonical)
    +      return true;
    +  return false;
    +}
    +
    +static bool
    +hasLoopLastprivateVariable(const OMPLoopDirective &S,
    +                           llvm::function_ref<bool(const Expr *)> Pred) {
    +  for (const auto *C : S.getClausesOfKind<OMPLastprivateClause>()) {
    +    for (const Expr *E : C->varlist()) {
    +      if (Pred(E))
    +        return true;
    +    }
    +  }
    +  return false;
    +}
    +
     static bool canEmitGPUNoLoopKernel(CodeGenModule &CGM,
                                        const OMPLoopDirective &S) {
       const auto *D = dyn_cast<OMPTargetTeamsDistributeParallelForDirective>(&S);
    @@ -3772,6 +3795,10 @@ emitInnerParallelForWhenCombined(CodeGenFunction &CGF,
           CGF.EmitOMPPrivateLoopCounters(S, PrivateScope);
           (void)PrivateScope.Privatize();
     
    +      CodeGenFunction::OMPPrivateScope LastprivateScope(CGF);
    +      (void)CGF.EmitOMPLastprivateClauseInit(S, LastprivateScope);
    +      (void)LastprivateScope.Privatize();
    +
           if (isOpenMPTargetExecutionDirective(EKind))
             CGM.getOpenMPRuntime().adjustTargetSpecificDataForLambdas(CGF, S);
     
    @@ -3795,17 +3822,33 @@ emitInnerParallelForWhenCombined(CodeGenFunction &CGF,
               CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());
           llvm::OpenMPIRBuilder &OMPBuilder =
               CGM.getOpenMPRuntime().getOMPBuilder();
    +      bool NeedsLastprivateFinalCopy = hasLoopLastprivateVariable(
    +          S, [&S](const Expr *E) { return !isLoopCounter(S, E); });
     
           cantFail(OMPBuilder.applyWorkshareLoop(
               CGF.Builder.getCurrentDebugLocation(), CLI, AllocaIP,
    -          /*NeedsBarrier=*/!S.getSingleClause<OMPNowaitClause>(),
    +          /*NeedsBarrier=*/!S.getSingleClause<OMPNowaitClause>() ||
    +              NeedsLastprivateFinalCopy,
               llvm::omp::OMP_SCHEDULE_Default,
               /*ChunkSize=*/nullptr, /*HasSimdModifier=*/false,
               /*HasMonotonicModifier=*/false, /*HasNonmonotonicModifier=*/false,
               /*HasOrderedClause=*/false,
               llvm::omp::WorksharingLoopType::DistributeForStaticLoop,
               /*NoLoop=*/true, /*HasDistSchedule=*/false,
    -          /*DistScheduleChunkSize=*/nullptr));
    +          /*DistScheduleChunkSize=*/nullptr,
    +          /*NeedsLastIter=*/NeedsLastprivateFinalCopy));
    +
    +      // Emit final copy for lastprivate variables, excluding counters deferred
    +      // to the distribute level.
    +      if (NeedsLastprivateFinalCopy) {
    +        llvm::Value *LastIter = CLI->getLastIter();
    +        assert(LastIter && "workshare loop did not publish last iteration");
    +        CGF.EmitOMPLastprivateClauseFinal(
    +            S, /*NoFinals=*/true,
    +            CGF.Builder.CreateIsNotNull(CGF.Builder.CreateAlignedLoad(
    +                CGF.Int32Ty, LastIter, CharUnits::fromQuantity(4),
    +                ".omp.is_last")));
    +      }
           return;
         }
     
    @@ -6364,8 +6407,11 @@ void CodeGenFunction::EmitOMPDistributeLoop(const OMPLoopDirective &S,
               !isOpenMPTeamsDirective(S.getDirectiveKind()))
             EmitOMPReductionClauseInit(S, LoopScope);
     
    +      // Defer lastprivate init to the parallel region for no-loop
           const bool NoLoopKernel = canEmitGPUNoLoopKernel(CGM, S);
    -      HasLastprivateClause = EmitOMPLastprivateClauseInit(S, LoopScope);
    +      if (!NoLoopKernel)
    +        HasLastprivateClause = EmitOMPLastprivateClauseInit(S, LoopScope);
    +
           EmitOMPPrivateLoopCounters(S, LoopScope);
           (void)LoopScope.Privatize();
           if (isOpenMPTargetExecutionDirective(S.getDirectiveKind()))
    @@ -6501,11 +6547,17 @@ void CodeGenFunction::EmitOMPDistributeLoop(const OMPLoopDirective &S,
                                          CodeGenLoop);
             }
           }
    -      if (isOpenMPSimdDirective(S.getDirectiveKind())) {
    -        EmitOMPSimdFinal(S, [IL, &S](CodeGenFunction &CGF) {
    -          return CGF.Builder.CreateIsNotNull(
    -              CGF.EmitLoadOfScalar(IL, S.getBeginLoc()));
    -        });
    +      if (isOpenMPSimdDirective(S.getDirectiveKind()) ||
    +          (NoLoopKernel && hasLoopLastprivateVariable(S, [&S](const Expr *E) {
    +             return isLoopCounter(S, E);
    +           }))) {
    +        EmitOMPSimdFinal(
    +            S, [IL, &S, NoLoopKernel](CodeGenFunction &CGF) -> llvm::Value * {
    +              if (NoLoopKernel)
    +                return nullptr;
    +              return CGF.Builder.CreateIsNotNull(
    +                  CGF.EmitLoadOfScalar(IL, S.getBeginLoc()));
    +            });
           }
           if (isOpenMPSimdDirective(S.getDirectiveKind()) &&
               !isOpenMPParallelDirective(S.getDirectiveKind()) &&
    diff --git a/clang/test/OpenMP/target_no_loop.c b/clang/test/OpenMP/target_no_loop.c
    index 0fe3de1780cce..d754331f3f87b 100644
    --- a/clang/test/OpenMP/target_no_loop.c
    +++ b/clang/test/OpenMP/target_no_loop.c
    @@ -45,12 +45,37 @@ void no_loop_simd(int *array) {
         array[i] = i + 1;
     }
     
    +void no_loop_lastprivate_counter(int *array) {
    +  int i;
    +#pragma omp target teams distribute parallel for lastprivate(i)
    +  for (i = 0; i < 1024; ++i)
    +    array[i] = i + 1;
    +}
    +
    +void no_loop_lastprivate_scalar(int *array) {
    +  int last = 0;
    +#pragma omp target teams distribute parallel for lastprivate(last)
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +}
    +
     void no_loop_nowait(int *array) {
     #pragma omp target teams distribute parallel for nowait
       for (int i = 0; i < 1024; ++i)
         array[i] = i + 1;
     }
     
    +void no_loop_lastprivate_scalar_nowait(int *array) {
    +  int last = 0;
    +#pragma omp target teams distribute parallel for lastprivate(last) nowait
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +}
    +
     // NOLOOP: no_loop_l{{[0-9]+}}_kernel_environment {{.*}} i8 0, i8 1, i8 6
     // NOLOOP: no_loop_simd_l{{[0-9]+}}_kernel_environment {{.*}} i8 0, i8 1, i8 6
     
    @@ -71,6 +96,25 @@ void no_loop_nowait(int *array) {
     // NOLOOP: omp_loop.after:
     // NOLOOP-NEXT: ret void
     
    +// NOLOOP-LABEL: @__kmpc_parallel_60({{.*}}lastprivate_counter{{.*}})
    +// NOLOOP: omp.loop.exit:
    +// NOLOOP-NEXT: store i32 1024, ptr %i
    +// NOLOOP-NEXT: @__kmpc_free_shared(ptr %i{{.*}})
    +// NOLOOP-NEXT: ret void
    +// NOLOOP: @__kmpc_distribute_for_static_loop_4u({{.*}}lastprivate_counter{{.*}}, i32 0, i32 0, i8 1)
    +// NOLOOP: @__kmpc_barrier
    +// NOLOOP: omp_loop.after:
    +// NOLOOP-NEXT: ret void
    +
    +// NOLOOP-LABEL: @__kmpc_parallel_60({{.*}}lastprivate_scalar{{.*}})
    +// NOLOOP: omp.loop.exit:
    +// NOLOOP-NEXT: @__kmpc_free_shared(ptr %last{{.*}})
    +// NOLOOP-NEXT: ret void
    +// NOLOOP: @__kmpc_distribute_for_static_loop_4u({{.*}}lastprivate_scalar{{.*}}, i32 0, i32 0, i8 1)
    +// NOLOOP: @__kmpc_barrier
    +// NOLOOP: store {{.*}}, ptr %last.
    +// NOLOOP-NEXT: %.omp.lastprivate.done
    +
     // NOLOOP-LABEL: @__kmpc_parallel_60({{.*}}no_loop_nowait{{.*}})
     // NOLOOP: omp.loop.exit:
     // NOLOOP-NEXT: ret void
    @@ -80,4 +124,13 @@ void no_loop_nowait(int *array) {
     // NOLOOP: omp_loop.after:
     // NOLOOP-NEXT: ret void
     
    -// SPMD-COUNT-3: _kernel_environment {{.*}} i8 0, i8 1, i8 2
    +// NOLOOP-LABEL: @__kmpc_parallel_60({{.*}}lastprivate_scalar_nowait{{.*}})
    +// NOLOOP: omp.loop.exit:
    +// NOLOOP-NEXT: @__kmpc_free_shared(ptr %last{{.*}})
    +// NOLOOP-NEXT: ret void
    +// NOLOOP: @__kmpc_distribute_for_static_loop_4u({{.*}}lastprivate_scalar_nowait{{.*}}, i32 0, i32 0, i8 1)
    +// NOLOOP: @__kmpc_barrier
    +// NOLOOP: store {{.*}}, ptr %last.
    +// NOLOOP-NEXT: %.omp.lastprivate.done
    +
    +// SPMD-COUNT-6: _kernel_environment {{.*}} i8 0, i8 1, i8 2
    diff --git a/offload/test/offloading/target-no-loop.c b/offload/test/offloading/target-no-loop.c
    index 59558c67152e2..ae6c31c966b19 100644
    --- a/offload/test/offloading/target-no-loop.c
    +++ b/offload/test/offloading/target-no-loop.c
    @@ -72,6 +72,48 @@ int main(void) {
       if (red != 1024)
         ++errors;
     
    +  // No-loop kernel with a lastprivate variable (final value from thread executing last iteration)
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +
    +  int last = -1;
    +#pragma omp target teams distribute parallel for lastprivate(last)
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE
    +  if (last != 1023)
    +    ++errors;
    +#endif
    +
    +  // No-loop kernel with a lastprivate loop counter (final value from evaluation at distribution level)
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +  int iv = -1;
    +#pragma omp target teams distribute parallel for lastprivate(iv)
    +  for (iv = 0; iv < 1024; ++iv)
    +    array[iv] = iv + 1;
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE
    +  if (iv != 1024)
    +    ++errors;
    +#endif
    +
    +  // No-loop simd kernel with a lastprivate loop counter
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +  int simd_iv = -1;
    +#pragma omp target teams distribute parallel for simd lastprivate(simd_iv)
    +  for (simd_iv = 0; simd_iv < 1024; ++simd_iv)
    +    array[simd_iv] = simd_iv + 1;
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE
    +  if (simd_iv != 1024)
    +    ++errors;
    +#endif
    +
       printf("number of errors: %d\n", errors);
       return 0;
     }
    @@ -88,4 +130,10 @@ int main(void) {
     // CHECK:  info: #Args: 2 Teams x Thrds:   16x  16 {{.*}}
     // CHECK:  PluginInterface device {{[0-9]+}} info: Launching kernel {{.*}} SPMD mode
     // CHECK:  info: #Args: 3 Teams x Thrds:   16x  16 {{.*}}
    +// CHECK:  PluginInterface device {{[0-9]+}} info: Launching kernel {{.*}} SPMD-No-Loop mode
    +// CHECK:  info: #Args: 3 Teams x Thrds:   64x  16 {{.*}}
    +// CHECK:  PluginInterface device {{[0-9]+}} info: Launching kernel {{.*}} SPMD-No-Loop mode
    +// CHECK:  info: #Args: 3 Teams x Thrds:   64x  16 {{.*}}
    +// CHECK:  PluginInterface device {{[0-9]+}} info: Launching kernel {{.*}} SPMD-No-Loop mode
    +// CHECK:  info: #Args: 3 Teams x Thrds:   64x  16 {{.*}}
     // CHECK:  number of errors: 0
    
    
    ``````

    </details>

    github-actions[bot] github-actions[bot] commented on Oct 06, 2026 07:22 UTC
    Bot

    <!--PREMERGE ADVISOR COMMENT: Windows-->

    :window: Windows x64 Test Results

    61583 tests passed
    2014 tests skipped

    :white_check_mark: The build succeeded and all tests passed.

    ro-i ro-i commented on code on Oct 13, 2026 15:55 UTC
    Code Review
    clang/lib/CodeGen/CGStmtOpenMP.cpp:1
    @@ -75,6 +75,29 @@ static bool canEmitGPUFusedDistSchedule(const CodeGenModule &CGM,
              !S.getSingleClause<OMPOrderedClause>();
     }
     
    +static bool isLoopCounter(const OMPLoopDirective &S, const Expr *E) {
    +  const VarDecl *Canonical =
    +      cast<VarDecl>(cast<DeclRefExpr>(E->IgnoreParenImpCasts())->getDecl())
    +          ->getCanonicalDecl();
    +  for (const Expr *C : S.counters())

    please add braces around the outer statements if there are nested statements (there was some discourse discussion driven by Shilei at some point)

    ro-i ro-i commented on Oct 13, 2026 16:14 UTC
    Reviewer

    lgtm in general, but not sure I understand "forcing the exit barrier the copy reads through". What do you mean by that exactly?

    dhruvachak dhruvachak commented on Oct 26, 2026 21:33 UTC
    Contributor

    Can you resolve the conflicts please?

    dhruvachak dhruvachak commented on code on Oct 30, 2026 01:43 UTC
    Code Review
    offload/test/offloading/target-no-loop.c:1
    @@ -72,6 +72,48 @@ int main(void) {
       if (red != 1024)
         ++errors;
     
    +  // No-loop kernel with a lastprivate variable (final value from thread executing last iteration)
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +
    +  int last = -1;
    +#pragma omp target teams distribute parallel for lastprivate(last)
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE

    Why under an ifdef that is not defined? So this is never checked? Multiple similar uses below.

    dhruvachak dhruvachak commented on Oct 30, 2026 02:22 UTC
    Contributor

    Using text from the commit message, can you explain why you are "forcing
    the exit barrier the copy reads through"? And can it be optimized for no-wait?

    nicebert nicebert commented on code on Oct 30, 2026 08:26 UTC
    Code Review
    offload/test/offloading/target-no-loop.c:1
    @@ -72,6 +72,48 @@ int main(void) {
       if (red != 1024)
         ++errors;
     
    +  // No-loop kernel with a lastprivate variable (final value from thread executing last iteration)
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +
    +  int last = -1;
    +#pragma omp target teams distribute parallel for lastprivate(last)
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE

    The assertions on the final value are guarded because they can't pass with current clang, independent of this PR. A scalar lastprivate on a combined target construct is currently passed to the kernel by value, so its final value is never copied back to the host.
    Since OpenMP 5.0, list items in a reduction, lastprivate or linear clause on a combined target construct should be treated as if they were mapped as tofrom. This was implemented for reduction items but not for lastprivate, and there is an open issue for it (since 2021): llvm/llvm-project#49496. I intentionally did not fix it in this PR.
    I can either drop the guarded checks until the issue is fixed, or keep them and add an explicit map(tofrom: last) to the pragmas so they run today. Which would you prefer?

    nicebert nicebert commented on Oct 30, 2026 10:21 UTC
    Author

    Using text from the commit message, can you explain why you are "forcing the exit barrier the copy reads through"? And can it be optimized for no-wait?

    The barrier was there because I carried over the rule from clang's regular worksharing loop, which emits the end-of-loop barrier even with nowait when there is a lastprivate. The wording in the commit message was wrong, the copy doesn't depend on it: only the thread that executed the last iteration does the copy, and it reads its own private copy and its own last-iteration flag, so it doesn't wait on any other thread. The end of the parallel region already synchronizes all threads after the copy. So yes, with nowait the barrier can be dropped, which I did in a2a1471e8d21, and I updated the PR description accordingly.

    dhruvachak dhruvachak commented on code on Nov 01, 2026 07:02 UTC
    Code Review
    offload/test/offloading/target-no-loop.c:1
    @@ -72,6 +72,48 @@ int main(void) {
       if (red != 1024)
         ++errors;
     
    +  // No-loop kernel with a lastprivate variable (final value from thread executing last iteration)
    +  for (int i = 0; i < 1024; ++i)
    +    array[i] = 1;
    +
    +  int last = -1;
    +#pragma omp target teams distribute parallel for lastprivate(last)
    +  for (int i = 0; i < 1024; ++i) {
    +    array[i] = i + 1;
    +    last = i;
    +  }
    +  errors += check_errors(array);
    +#ifdef ASSERT_LASTPRIVATE

    I would prefer adding the explicit map tofrom. That way, we would have more coverage for the lastprivate codepath in this PR.

    dhruvachak dhruvachak approved these changes on Nov 03, 2026 16:50 UTC
    Approved Reviewer

    LGTM

    github-actions[bot] github-actions[bot] commented on Nov 09, 2026 14:52 UTC
    Bot

    <!--PREMERGE ADVISOR COMMENT: Linux-->

    :penguin: Linux x64 Test Results

    96622 tests passed
    4398 tests skipped

    :white_check_mark: The build succeeded and all tests passed.

    Reviewers
    Assignees
    nicebert nicebert
    Labels
    risk: low confidence: 87.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.9% (MEDIUM) · Higher = larger blast radius
    43.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.7% · Lower = rushed or shallow review
    87.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.4% · Safe to merge
    5.4%