Repository navigation
Conversation
The Cartesian linear index was computed as `i + n1 * ((j + n2 * (k - 1)) - 1)`, subtracting one from the partial sums. With Julia v1.12 and newer (LLVM 18+), the loop vectorizer does not vectorize short loops over an index of a `FixedSizeArray` with this form. Computing the zero-based offset `(i - 1) + n1 * ((j - 1) + n2 * (k - 1))` and adding one at the end has the same number of integer operations and vectorizes. Assisted-by: Claude Code (Fable 5.2)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #236 +/- ##
==========================================
+ Coverage 94.73% 95.48% +0.74%
==========================================
Files 8 8
Lines 323 332 +9
==========================================
+ Hits 306 317 +11
+ Misses 17 15 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
giordano
reviewed
Nov 26, 2026
giordano
left a comment
Member
There was a problem hiding this comment.
Sounds like a FileCheck test would help?
…n element Since Julia v1.13, with the zero-based Horner form of the Cartesian linear index the loop vectorizer needs no runtime check that the index does not wrap (`vector.scevcheck`) and no scalar fallback loop for short loops over the nodes of an element. These tests fail with the previous form of the index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016cX3ig3MD9aPL8rgQRif5v
Member
I pushed a test, but the bot couldn't find a loop which solves the missed optimisation in Julia v1.12, apparently this is only solved in v1.13+ |
Member
|
Also, this branch makes this test from #217 FixedSizeArrays.jl/test/filecheck.jl Lines 557 to 569 in ab67d3f --check-bounds=auto (which is a combination we don't run here on CI). Compilers are fun 🫠
|
This branch has not been deployed
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.
Cartesian
getindex/setindex!compute the linear index in Horner form asThis PR changes the association to
The number of integer operations is the same, but starting with Julia v1.12 (LLVM 18) the loop vectorizer does not vectorize short loops over an index of a
FixedSizeArraywith the current form.Measurements
Gather-form derivative kernel over a
FixedSizeArrayDimswith dimensions(Val(1), Val(4), Val(4), Val(4), n), minimum time in µs, x86-64 (Ryzen 9 5950X), one pinned core:The same kernel with a hand-written wrapper type using either index form reproduces both columns, so the difference is the index expression and not something else in
FixedSizeArray. A sum of strided terms (1 + (i - 1) + n1 * (j - 1) + ...) does not vectorize on 1.12/1.14 either.In Trixi.jl (trixi-framework/Trixi.jl#3357, 3D p4est advection, Julia 1.14):
rhs!307–320 µs → 290–302 µs, interface flux 84–86 µs → 62–65 µs, volume integral 180–184 µs → 167–175 µs. One kernel (prolong2interfaces!) gets slower, 23 µs → 32 µs, because LLVM unrolls its node loop differently; that is fixable in the Trixi.jl kernel and independent of the index form otherwise.Open points (hence draft)
tree_3d_dgsem/elixir_euler_ec.jl1784 → 1760,p4est_3d_dgsem/elixir_euler_ec.jl1110 → 1110,tree_2d_dgsem/elixir_euler_ec.jl542–588 → 552–562,p4est_2d_dgsem/elixir_euler_shockcapturing_ec.jl369 → 365. So for compressible Euler this PR is neutral; the gains above are for scalar advection.FixedSizeArrayfor adaptors that are not array types #235 (both add an "Unreleased" section).The existing test suite passes locally on Julia 1.14.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HgDfyeGjfcC7cikr7MfRB3