Skip to content

Preserve types on reverse cache reloads - #3156

Merged
wsmoses merged 2 commits into
EnzymeAD:mainfrom
vimarsh6739:vim/julia13-tape-types
Sep 10, 2026
Merged

wsmoses merged 2 commits into
EnzymeAD:mainfrom
vimarsh6739:vim/julia13-tape-types

Conversation

@vimarsh6739

Copy link
Copy Markdown
Member

Reverse cache reloads created by lookupM dropped the original TypeTree. Preserve it as enzyme_type metadata so nested differentiation can classify cached integer loop indices.

Adds a focused check to bsearch2.ll. Tracks EnzymeAD/Enzyme.jl#3472.

Attach the original TypeTree to values restored from reverse caches so nested differentiation can classify cached integer loop indices.

Assisted-by: OpenAI Codex
@vimarsh6739
vimarsh6739 enabled auto-merge August 20, 2026 17:03
@vchuravy

Copy link
Copy Markdown
Member

Ah claude came up with a similar fix in #3202

@wsmoses
wsmoses disabled auto-merge September 10, 2026 16:06
@wsmoses
wsmoses merged commit a71da72 into EnzymeAD:main Sep 10, 2026
32 of 34 checks passed
vchuravy added a commit that referenced this pull request Sep 10, 2026
#3156 records the original TypeTree as `!enzyme_type` on values restored from
reverse caches, but attaches whatever `TR.query` returns without checking it
against the reload's register size.

`TypeAnalyzer::considerTBAA` does check, and treats a violation as fatal:

    if ((size_t)pair.first[0] >= RegSize) {
      llvm::errs() << " bad enzyme_type " << TT.str() << ...;
      llvm::report_fatal_error("Canonicalization failed");
    }

So a tree with an offset past the register size does not degrade the analysis,
it aborts the next type analysis run over the generated function -- which is
exactly the nested-differentiation case (forward-over-reverse) the metadata was
added to serve.

Apply the same range check before setting the metadata and drop the tree when
it does not hold. Dropping only returns that reload to the pre-#3156 behaviour
of an untyped load, which is the conservative direction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RD6pJCuKKB1n9L8k2orUua
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.

3 participants