AffineCFG: a conditional a loop bound reads is written as an indicator #3425
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.53) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.53 · 471 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.368
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3425"
general
weight: 0.35
ImanHosseini
MFEM's 3D hdiv/hcurl kernels (
PAHdivL2Apply3D,PAHdivL2AssembleDiagonal_ADAt_3D,PAHdivMassSetup3D, …) size an inner loop by the vector componentc, the variable of a constant-trip loop inside the element lambda. For example,PAHdivMassAssembleDiagonal3D(fem/integ/bilininteg_hdiv_kernels.cpp):``
c++
`mfem::forall(NE, [=] MFEM_HOST_DEVICE (int e)
{
int osc = 0;
for (int c = 0; c < VDIM; ++c) // VDIM = 3
{
const int D1Dz = (c == 2) ? D1D : D1D - 1;
...
for (int dz = 0; dz < D1Dz; ++dz)
...
osc += D1Dx D1Dy D1Dz;
}
});
The hcurl kernels have the arms the other way round ((c == 2) ? D1D - 1 : D1D
).D1Dis a symbol, butD1Dzis not: it differs from oneciteration to the next. So thedzbound is a function of the loop variablec.This reaches affine-cfg
as anaffine.ifovercyielding two constants (orD1D - 1/D1D) that feeds anscf.forbound. That loop has no affine bound, so it stays anscf.for, its stores staymemref.store, and every loop around it is rejected for parallelization because of them (118 of the 293 rejections in the hdiv TU). The one existing pattern for this,SplitOnAffineIfConstants, duplicates the loop per arm and is off in the pipeline.The rewrite
When the if
's operands are loop variables with constant bounds, its constraintchas a constant range[lo, hi]. Over that range the condition is an affine expression:, withM = max(hi + 1, -lo)AffineIfConstantsAsIndicator<scf::ForOp>
/<scf::IfOp>finds the conditional an op's bounds or condition derive from, usingSplitOnAffineIfConstants::findConditionalwith the arm test now a parameter. Each arm pair must be two constants, or two values a constant apart (D1D - 1/D1D) where the else arm is defined at the scope's top level, so it can be used as a symbol. The conditional's result becomesb + (a - b) indicator, anaffine.apply, with anindex_castback to the yielded type.ForOpRaisingthen takes the bound, e.g.D1D - 1 + c floordiv 2overc ∈ [0, 2]for the hdiv form.The rewrite only applies where a loop bound or an scf.if
condition reads the result. Anaffine.ifof constants anywhere else stays a set that the domain simplifications can read. Applying it everywhere lost a loop merge inraiseimmerse.mlirandaffinecfg_ext.mlir.Effect
Running --affine-cfg
alone on the MFEM dumps:scf.forleft inbilininteg_hdiv_kernels.cpp61 → 19, and inbilininteg_hcurl_kernels.cpp20 → 5.The floordiv
in the indicator goes throughlower-affineand back in the pipeline. #3451 (merged, split out of this PR) makesmatchLoweredDivread it back. Without #3451, compilingbilininteg_curlcurl_pa,bilininteg_mixedcurl_paandtest_curlcurl_integfailed.With this change on the earlier MFEM stack (sweep final48), the newly batched SmemPAHdivMassApply3D<3,4>
matched a NumPy reference to 1e-14, and the MFEM GPU suite was 74/74.Tests
:==and>=constraints, value arms a constant apart, and a conditional that stays because nothing bounds a loop with it.: the split cases now use a loop variable of unknown extent. Over a constant range the indicator applies first, with no duplication.Interaction with other open PRs (rebased on main 73603ba52): with #3431, affinecfg_split_on_flag
@xor_flag's 0/-1affine.ifbecomes this PR's indicatoraffine.apply`; correct output, regenerate on whichever lands second.🤖 Generated with Claude Code
https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD