Skip to content

[MemDep] Backport: Stop traversal if invariant.group load operand is a constant - #73

Merged
vchuravy merged 1 commit into
JuliaLang:julia-release/20.xfrom
vchuravy:vc/backport-223456-20.x
Dec 4, 2026
Merged

vchuravy merged 1 commit into
JuliaLang:julia-release/20.xfrom
vchuravy:vc/backport-223456-20.x

Conversation

@vchuravy

@vchuravy vchuravy commented Dec 3, 2026

Copy link
Copy Markdown
Member

Backport of llvm#223456 (11f5331), cherry-picked with -x. The cherry-pick applied with no conflicts.

MemoryDependenceResults::getInvariantGroupPointerDependency walks the users of the pointer operand of a load that has !invariant.group. On this branch it stops only when the pointer is a GlobalValue. For any other constant, the walk reaches instructions in other functions of the module. The upstream fix changes isa<GlobalValue> to isa<Constant>.

This is the cause of EnzymeAD/Enzyme.jl#4153 on Julia 1.13. Enzyme puts !invariant.group on loads in the reverse pass, and the address of a Julia object is a constant inttoptr expression. When two functions load through the same constant, GVN replaces the load with a load from the other function. The verifier then reports "Referring to an instruction in another function!", or ADCE crashes.

Testing, on a Release+Assertions X86-only build of this branch (opt, FileCheck, llvm-as, llvm-dis):

  • llvm-lit llvm/test/Transforms/GVN llvm/test/Transforms/NewGVN llvm/test/Analysis/MemoryDependenceAnalysis: 392 tests, 374 passed, 18 expectedly failed, 0 failed.
  • The new llvm/test/Transforms/GVN/strict-vtable.ll fails without the source change and passes with it.
  • opt -passes=gvn on the two-function IR from the Enzyme.jl issue keeps both loads.
  • I have not built Julia against this branch or run the Enzyme.jl reproducer with it.

🤖 Generated with Claude Code

…llvm#223456)

When traversing a load with attached invariant.group metadata, MemDep
analysis can start looking outside the function that the GVN pass is
being run on. This happens if the load operand is a constant expression
referencing a global object (e.g. a vtable pointer). The DominatorTree
then crashes with an assertion when analyzing two instructions from
different functions.

This issue causes a crash in clang when the `-fstrict-vtable-pointers`
option is used, see https://godbolt.org/z/sbKMa5K1d

(cherry picked from commit 11f5331)

[Backport to julia-release/20.x: the cherry-pick applied with no conflicts.]

Co-Authored-By: Claude <noreply@anthropic.com>
@vchuravy
vchuravy merged commit 3f3a7ee into JuliaLang:julia-release/20.x Dec 4, 2026
4 checks passed
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