← Back to Pull requests

Add concat_elementwise_slice #3715

Closed
unknown closed this pull request without merging on Oct 29, 2026 05:31 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 20:30 UTC
Author

concat(slice(op(a1, b1)), op(a2, b2), slice(op(a3, b3))) along a dimension, with the same elementwise op (name, attributes, operand count and element types) behind every piece and at least one piece a slice of it, becomes op(concat(slice(a1), a2, slice(a3)), concat(slice(b1), b2, slice(b3))).

ConcatElementwise covers the case where the pieces are the ops themselves and used only by the concatenate. Here the ops may have other users (so the op is computed once more over the concatenate's extent), which lets the slices reach the sources and the concatenate become one of views; the slices themselves must be used only by the concatenate, since one that survives the rewrite leaves nothing gained.

The rewrite is made only when at most one operand position needs a concatenate of its own, the others being one value already: the same splat constant, the same scalar broadcast, or adjacent windows of one source in order (a slice of it, or the source itself). Deciding and building are shared helpers in Utils: classifyConcatPieces (on canMergeSlicesAlongAxis) says what a concatenate of windows of values amounts to, and ConcatenatePiecesCreate emits the one value or else the concatenate with adjacent slices merged (concatSliceSimplify, ConcatenateOpCreate); the pattern only counts and builds. The concatenate then moves down the chain of the one computed operand (through unary ops, and ops with a constant or shared operand) and never multiplies. Hoisting over two computed operands leaves a concatenate per operand at every level, measured on the Breeze WENO tendency modules as 13 concatenates instead of 5 (scalar) and 73 instead of 40 (model), 10-30% slower.

Motivating case (Breeze.jl model tendency, WENO5, Reactant 0.2.300; see #3712): a boundary choice between two shifted reads of the same field,

%518  = stablehlo.multiply %15, %cst_80      ; %15 = slice %arg16 [3:131, ...]
%377  = stablehlo.multiply %33, %cst_80      ; %33 = slice %arg16 [4:132, ...]
%1856 = stablehlo.slice %518 [0:3, ...]
%1855 = stablehlo.slice %377 [3:127, ...]
%1857 = stablehlo.slice %518 [127:128, ...]
%1858 = stablehlo.concatenate %1856, %1855, %1857, dim = 0

where slice_elementwise cannot move the slices through the multiplies (they have other users) and concat_elementwise does not apply (the pieces are slices). It becomes multiply(concat(arg16[3:6], arg16[7:131], arg16[130:131]), cst) once slice_slice folds, with the constant concatenate folded by concat_const_prop.

Added to the base pattern list. On the dumped Breeze modules as they leave the 0.2.300 pipeline the rewrite is neutral on its own (same concatenate counts, same timings within noise, outputs bitwise identical). Together with the end-of-pipeline stage of #3712 it is also neutral (RTX 5090, min of three, ms per call: scalar WENO5 0.337 with the stage alone, 0.342 with both; model WENO5 2.353 and 2.388, against 1.914 for the 0.2.292 form): the hoisted concatenate is one of views, which that stage leaves alone by design, and the sink step then splits the computation downstream of it into five per-range pieces at the output. Closing the remaining model WENO5 gap means treating that concatenate of views as a select in the stage, a separate change.

Tests: concat_elementwise_slice.mlir; the autobatching while_reverse_no_autobatching.mlir now sees more hoisted constants before its loops, so its loop-argument names are matched by pattern. Full lit suite passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1GPCnUaQKiMLASni1N1eu

Diff: 450 lines (+337 / -113) across 5 files Reviewer: ftynse Review duration: 1981m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 450 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.366
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3715"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 45.4% (MEDIUM) · Higher = larger blast radius
45.4%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 17.9% · Safe to merge
17.9%