Skip to content

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Sep 12, 2025

  • Use svec instead of tuple for arguments (better match for ABI which will require boxes)
  • Directly forward single svec argument, both runtime and codegen, without copying.
  • Optimize all consistant builtin functions of constant arguments, not just ones with special tfuncs. Reducing code duplication and divergence.
  • Codegen for svec() directly, so optimizer can see each store (and doesn't have to build the whole thing on the stack first).

Written by Claude

@vtjnash vtjnash changed the title optimizations: better modeling and codegen for apply calls optimizations: better modeling and codegen for apply and svec calls Sep 12, 2025
Comment on lines +1423 to +1425
elseif is_known_call(stmt, Core._apply_iterate, compact)
length(stmt.args) >= 4 || continue
lift_apply_args!(compact, idx, stmt, 𝕃ₒ)
Copy link
Member

Choose a reason for hiding this comment

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

Just commenting for reference, and we don't have to do this in this PR, but I startd to think it'd be better to make this kind of optimization independent of sroa_pass!.

Copy link
Member Author

Choose a reason for hiding this comment

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

We might want to instead just rename the pass GVN or MemSSAOpt, since doing everything in one pass is probably a lot more efficient, and either alternative name would reflect that this does general memory-value-replacement optimizations

 - Use svec instead of tuple for arguments (better match for ABI which
   will require boxes)
 - Directly forward single svec argument, both runtime and codegen,
   without copying.
 - Optimize all consistant builtin functions of constant arguments, not
   just ones with special tfuncs. Reducing code duplication and
   divergence.
 - Codegen for `svec()` directly, so optimizer can see each store (and
   doesn't have to build the whole thing on the stack first).
Without a release store, it seems LLVM considers it a data race to have
read the initial state on another thread. Marking this as a release
store seems sufficient to prevent that optimization. It is also more
consistent with how we initialize and write to most other structs,
particularly since #55767.

Fixes #59547 (more)
@vtjnash vtjnash added the don't squash Don't squash merge label Sep 16, 2025
@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Sep 17, 2025
@vtjnash vtjnash merged commit f818842 into master Sep 17, 2025
9 checks passed
@vtjnash vtjnash deleted the jn/svec-opt-apply branch September 17, 2025 17:06
aviatesk pushed a commit that referenced this pull request Sep 19, 2025
…59548)

- Use svec instead of tuple for arguments (better match for ABI which
will require boxes)
- Directly forward single svec argument, both runtime and codegen,
without copying.
- Optimize all consistant builtin functions of constant arguments, not
just ones with special tfuncs. Reducing code duplication and divergence.
- Codegen for `svec()` directly, so optimizer can see each store (and
doesn't have to build the whole thing on the stack first).

Written with help by Claude
@aviatesk aviatesk removed the backport 1.12 Change should be backported to release-1.12 label Sep 19, 2025
@aviatesk
Copy link
Member

Backported to 1.12.

aviatesk added a commit that referenced this pull request Sep 19, 2025
Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.
aviatesk added a commit that referenced this pull request Sep 22, 2025
#59601)

Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.
aviatesk added a commit that referenced this pull request Sep 22, 2025
#59601)

Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.
KristofferC pushed a commit that referenced this pull request Sep 24, 2025
#59601)

Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.

(cherry picked from commit a4e02ca)
KristofferC pushed a commit that referenced this pull request Sep 30, 2025
#59601)

Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.

(cherry picked from commit a4e02ca)
KristofferC pushed a commit that referenced this pull request Sep 30, 2025
#59601)

Further improves the implementation from #59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.

(cherry picked from commit a4e02ca)
@KristofferC KristofferC mentioned this pull request Sep 30, 2025
47 tasks
aviatesk added a commit that referenced this pull request Sep 30, 2025
Adds a dedicated `_svec_len_nothrow` function that does more precise
`:nothrow` modeling of `Core._svec_len` implemented in
#59548.
aviatesk added a commit that referenced this pull request Sep 30, 2025
Adds a dedicated `_svec_len_nothrow` function that does more precise
`:nothrow` modeling of `Core._svec_len` implemented in
#59548.
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
…Lang#59548 (JuliaLang#59601)

Further improves the implementation from JuliaLang#59548.
Specifically, uses `widenconst` to enable conversion of `tuple` calls
that have become `PartialStruct`, and removes incorrect comments and
unused arguments.

Also adds some Julia-IR level tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

don't squash Don't squash merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants