Skip to content

Experiment with the ipo effects on LLVM - #47844

Closed
gbaraldi wants to merge 10 commits into
JuliaLang:masterfrom
gbaraldi:ipo-effects-test
Closed

gbaraldi wants to merge 10 commits into
JuliaLang:masterfrom
gbaraldi:ipo-effects-test

Conversation

@gbaraldi

@gbaraldi gbaraldi commented Dec 9, 2022 •

Copy link
Copy Markdown
Member

I'm not sure about the correctness of this. Basically playing with it and asking for help.

This is very similar to what #32368 wanted to do

@brenhinkeller brenhinkeller added the compiler:llvm For issues that relate to LLVM label Dec 9, 2022
@vtjnash
vtjnash requested a review from aviatesk December 12, 2022 15:46
@gbaraldi

Copy link
Copy Markdown
Member Author

LLVM didn't really like speculatable coming there, I will need to think this a bit more through.

Comment thread src/codegen.cpp Outdated
Comment thread src/codegen.cpp
#if JL_LLVM_VERSION >= 140000
AttrBuilder attr(C);
#else
AttrBuilder attr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could prefix all of the custom string attributes with julia. to avoid any namespace collisions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they are there mostly for debugging, we probably want a smarter way to encode this

Comment thread src/codegen.cpp
attr.addAttribute("nothrow");
attr.addAttribute(Attribute::NoUnwind); // Is this even correct, because nothrow allows for try/catch
}
if (terminates == 1){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add mustprogress here too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

willreturn already implies mustprogress but I guess it's fine adding both

Comment thread src/codegen.cpp Outdated
Comment thread src/codegen.cpp Outdated
Comment thread src/codegen.cpp Outdated
Comment thread src/codegen.cpp
Comment on lines +576 to +582
if (nonoverlayed == 1)
attr.addAttribute("nonoverlayed");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well do you have some idea to use this attribute? It's very Julia-compiler specific attribute.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I just wanted to see if I was getting all the effects correctly at the LLVM level, those string like attributes were just for debugging.

@aviatesk aviatesk added needs pkgeval Tests for all registered packages should be run with this change compiler:effects effect analysis labels Dec 14, 2022
IanButterworth added a commit that referenced this pull request Apr 20, 2026
)

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)
- 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.

Previously explored in #47844

Developed with Claude

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gabriel Baraldi <28694980+gbaraldi@users.noreply.github.com>
hardikxk pushed a commit to hardikxk/julia that referenced this pull request May 18, 2026
…iaLang#61394)

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)
- 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.

Previously explored in JuliaLang#47844

Developed with Claude

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gabriel Baraldi <28694980+gbaraldi@users.noreply.github.com>
mkitti pushed a commit to mkitti/julia that referenced this pull request May 22, 2026
…iaLang#61394)

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)
- 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.

Previously explored in JuliaLang#47844

Developed with Claude

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Gabriel Baraldi <28694980+gbaraldi@users.noreply.github.com>
@adienes

adienes commented May 26, 2026

Copy link
Copy Markdown
Member

I suppose this was superseded by #61394 ?

@oscardssmith

Copy link
Copy Markdown
Member

Yes.

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

Labels

compiler:effects effect analysis compiler:llvm For issues that relate to LLVM needs pkgeval Tests for all registered packages should be run with this change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants