Repository navigation
Conversation
Translate Julia's inferred effects (consistent, effect_free, nothrow, terminates, notaskstate) into LLVM function attributes so that middle-end passes like GVN, LICM, and DSE can exploit them. The key design insight is that GC interactions don't need to be visible before GC lowering. Call-site declarations get optimistic memory attributes (e.g. memory(argmem: read)) that enable pre-GC optimizations, then LateLowerGCFrame widens them to memory(readwrite) before safepoint analysis so post-GC passes see correct semantics. Attributes added: - nounwind: for nothrow functions (with uwtable(async) on definitions to preserve .eh_frame for stack scanning) - mustprogress: for terminating functions - willreturn: for nothrow+terminating functions - memory(argmem: read): for consistent+effect_free functions with no user-facing pointer arguments (call-site declarations only) - speculatable: for the above when also nothrow+terminating - readnone on gcstack param: for notaskstate functions, so LICM can hoist pure calls past heap stores - "julia.safepoint" marker: on all call-site declarations, used by LateLowerGCFrame to identify and widen optimistic attrs LateLowerGCFrame strips all optimistic attributes (memory effects, readnone on gcstack) from both call instructions and function declarations before safepoint analysis runs. Co-Authored-By: Ian Butterworth <ibutterworth@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues #61394. Translates Julia's inferred
ipo_purity_bitsinto LLVM function attributes so that middle-end passes (GVN, LICM, DSE) can exploit them.memory(argmem: read)on pure functions lets GVN eliminate duplicate calls (e.g.fib(37)called twice after inlining → CSE'd to one call, ~1.3x speedup on recursive fib)exp(y)infor i in eachindex(x); x[i] = exp(y); end)speculatableon pure nothrow functions allows branch elimination viaselectDesign
The key insight is that GC interactions don't need to be visible before GC lowering. Call-site declarations get optimistic memory attributes for pre-GC optimization, then
LateLowerGCFramewidens them before safepoint analysis so post-GC passes see correct semantics.Attributes added by
add_fn_attrs_for_effects:nounwindnothrowuwtable(async)nothrow+ definition.eh_framefor stack scanningmustprogressterminateswillreturnnothrow + terminatesmemory(argmem: read)consistent + effect_free, no user ptr argsspeculatablenothrow + terminatesreadnoneon gcstacknotaskstate+ above"julia.safepoint"LateLowerGCFramecleanup (before safepoint analysis):memory(readwrite)on both call instructions and declarationsreadnonefrom gcstack parametersTest plan
make -C src analyze-{jitlayers,llvm-late-gc-lowering}for static analysisBase.runtests(["core", "Compiler/codegen", "Compiler/inference", "Compiler/inline", "worlds", "boundscheck", "exceptions", "arrayops"])— all passThis PR was developed with the assistance of generative AI.
Co-authored-by: Ian Butterworth ibutterworth@gmail.com
🤖 Generated with Claude Code