feat(isel): route *sat ops through GMIR #1926
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 298 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.341
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1926"
general
weight: 0.35
regehr
Routes the saturating intrinsics (
llvm.intr.{s,u}{add,sub,shl}.sat) through gMIR and the RISC-V 64legalizer, following LLVM's GlobalISel, instead of selecting them directly from the LLVM dialect with
SelectionDAG-style patterns.
For the legalization, we copy the patterns LLVM uses:
lowerAddSubSatToMinMaxlowerAddSubSatToAddoSubolowerShlSatlowerUAddSubOandlowerSAddSubOwidenScalarAddSubOverflowWe pick the
lowerAddSubSatToMinMaxlowering when the min/max ops are legal (s64) andlowerAddSubSatToAddoSubootherwise. This slightly differs from LLVM, which picks min/max when min/maxare legal or custom for the type, and addo/subo otherwise. However, afaict, implementing the same mechanism would be premature in our design as we would need multiple passes.
The generated code for the
i64sat intrinsics changes from SelectionDAG's sequences to GlobalISel's:{s,u}{add,sub}.satnow clamp with Zbbmin/max/minu(usub.satisx - minu x yinsteadof
maxu x y - y).{s,u}shl.satstill end in Zicond selects, now built from shifting the result back and comparing.Also, legalizing a
g_selectwith ani1condition coming from ag_icmpleft a redundant mask behind:%c = "gmir.g_icmp"(%x, %y) <{"predicate" = 2 : i64}> : (i64, i64) -> i1
%r = "gmir.g_select"(%c, %a, %b) : (i1, i64, i64) -> i64
became
%w = "gmir.g_icmp"(%x, %y) <{"predicate" = 2 : i64}> : (i64, i64) -> i64
%one = "gmir.g_constant"() <{"value" = 1 : i64}> : () -> i64
%m = "gmir.g_and"(%w, %one) : (i64, i64) -> i64
%r = "gmir.g_select"(%m, %a, %b) : (i64, i64, i64) -> i64
LLVM's
Legalizerkeeps two worklists. In each round it legalizes every non-artifact instruction first,then runs the artifact combiner. An artifact it cannot combine goes back to the instruction list and is
legalized in a later round.
Instead, our
legalizeInstrStepnow skips an artifact (g_trunc,g_[zsa]ext,g_merge_values,g_unmerge_values) while any of its operands is the result of a gMIR op that is not legal yet. In theexample, the
g_zextwaits. Theg_icmpis widened, and the combiner then foldsg_zext (g_trunc %w)to%w, matching LLVM.🤖 Assisted by Claude Code