Skip to content

Keep phis contiguous after inverting a phi's incoming values - #3126

Open
ZuseZ4 wants to merge 1 commit into
EnzymeAD:mainfrom
ZuseZ4:fix-e11-phi-contiguity
Open

Keep phis contiguous after inverting a phi's incoming values#3126
ZuseZ4 wants to merge 1 commit into
EnzymeAD:mainfrom
ZuseZ4:fix-e11-phi-contiguity

Conversation

@ZuseZ4

@ZuseZ4 ZuseZ4 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

In invertPointerM's PHINode case, inverting an incoming value can emit instructions into the phi's own block above the shadow phi just created -- materializing the shadow of a value defined in the loop header inserts an alloca, a store and byte-wise zeroing between the canonical IV phi and the shadow phi. That leaves the block's phis no longer contiguous at the block start, and the resulting IR is rejected:

Instruction does not dominate all uses!
PHI nodes not grouped at top of basic block!
function failed verification

One misplacement produces both complaints: the cache store for the primal phi is then emitted at getFirstNonPHI(), which now precedes that phi's definition.

Re-group the block's phis at the block start once the incoming values have been inverted.

Note this restores the invariant rather than preventing the insertion; the cleaner fix is to correct whichever builder positions the shadow-materialization machinery above the phis.

Workaround for #3029, though you might want to find the proper cause @wsmoses

In invertPointerM's PHINode case, inverting an incoming value can emit
instructions into the phi's own block above the shadow phi just created --
materializing the shadow of a value defined in the loop header inserts an
alloca, a store and byte-wise zeroing between the canonical IV phi and the
shadow phi. That leaves the block's phis no longer contiguous at the block
start, and the resulting IR is rejected:

  Instruction does not dominate all uses!
  PHI nodes not grouped at top of basic block!
  function failed verification

One misplacement produces both complaints: the cache store for the primal phi
is then emitted at getFirstNonPHI(), which now precedes that phi's definition.

Re-group the block's phis at the block start once the incoming values have
been inverted.

Note this restores the invariant rather than preventing the insertion; the
cleaner fix is to correct whichever builder positions the shadow-materialization
machinery above the phis.

Reduced test case reproducing the failure, and the instrumented-build evidence
localizing it to this site, are in the librint repro/ notes
(e11-reduced.ll, e11-verifier-phi.rs).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant