Skip to content

[AIEX] OuterLoopPipeliner Bug fix 1 #1072

Closed
F-Stuckmann wants to merge 22 commits into
aie-publicfrom
olp-fix1
Closed

[AIEX] OuterLoopPipeliner Bug fix 1 #1072
F-Stuckmann wants to merge 22 commits into
aie-publicfrom
olp-fix1

Conversation

@F-Stuckmann

@F-Stuckmann F-Stuckmann commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

@khallouh the first bug fix for the OuterLoopPipeliner. You can see that i only discovered it after extensive refactors.

I don't think properly porting the bug fix into nice 2 single commits is worth the effort, because the NFC refactor will clean up this intermediate state anyway again.

We may want to squash the refactors though.

Hoist the duplicated set.loop.iterations/start.loop.iterations intrinsic
predicate into a shared AIEIRUtils helper and call it from the outer-loop
pipeliner's cool-down and split-prologue paths.
Factor the repeated clone-then-remap idiom into cloneInstInto,
cloneAndRemapInsts, and remapClonesInto, and adopt them in
clonePrologueIntoEpilogue.
Replace the ad-hoc 'outer header == prologue' checks with a BlockRegion
wrapper and region-membership predicates (isRegionInternalPhi,
isPipelineableValue, isPipelineCandidate). Validation now flows through
discoverPrologueRegion and cloning through cloneRegionSubgraph; behaviour
stays linear-only (region == {outer.header}).
Split the ~160-line cool-down builder into named step helpers
(getExitBlock, cloneHardwareLoopSetupInto, createCooldownSkeleton,
cloneInnerLoopIntoCooldown, populateCooldownExit, wireCooldownIntoCFG) so
the body reads as an ordered list of intentions.
Mechanical rename of the split-prologue identifiers (collectPart2Instructions,
Part1Set/Part2Set, Part2Insts) to spelled-out PartOne/PartTwo forms.
Build the steady-state (N-1) loop and the peeled last iteration as fresh
cloned blocks, wire them into the CFG, and delete the original nest, instead
of mutating the original loop in place. The original and steady-state loop
structures now own disjoint blocks, removing the prior aliasing where one
LoopStructure's blocks changed meaning over the pass. Steady-state clone
blocks use the steady.* naming convention. Behavior-preserving: generated
assembly and pipeliner remarks are unchanged.
Rename the pipeliner's identifiers and IR block/value names to a consistent
scheme: the steady-state clone uses steady.* and the peeled last iteration uses
lastiter.* (replacing the prior warm-up / cool-down / cooldown terminology and
.cd suffixes). C++ helpers and locals follow suit (PartOneInsts, peelLastIteration,
LastIter*/Peel*). Pure renaming; generated assembly and pipeliner remarks are
unchanged.
Collapse multi-paragraph explanatory blocks and trailing end-of-line
comments to the one-to-two-line form, replacing prose with the code it
restates.
Validate the candidate loop inside the LoopStructure(Loop *) constructor
and cache the result, replacing the separate optional-returning analysis
helper. Now-internal analysis methods become private.
Extract the pipelining decision into a helper where each precondition is
a flat early return, leaving runOnLoop to own only the subloop recursion.
Add a shared AIEIRUtils helper for the @llvm.loop.decrement check and use
it from the inner-loop hardware-loop test instead of reimplementing the
intrinsic-matching boilerplate.
Captures pre-fix pipeliner output for two shapes: a latch-resident
accumulator and a non-phi latch def read after the loop. Both exit values
are computed from poison because the last-iteration epilogue drops the
loop-carried live-outs.
Source the last-iteration epilogue from the pristine original latch and
remap the outer-loop exit live-outs through the last-iteration clones, so a
value accumulated in (or carried out of) the latch and read after the loop
is computed correctly in the final iteration instead of from poison.
Regenerates the latch-accumulate and exit-no-phi tests to corrected output.
@martien-de-jong

Copy link
Copy Markdown
Collaborator

Can we at least have a description of the bug it fixes and a pointer to where it is fixed? This is unreviewable. I think squashing makes sense both jere and in the NFC PR.

@F-Stuckmann

Copy link
Copy Markdown
Collaborator Author

I am splitting the OLP refactor into NFC parts that reimplement the bugs and the fixes on top of the refactor. that will be clearer to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants