julia
8fa2d56c - Restore `@inbounds` in `fill!` for `Array`

Commit
22 days ago
Restore `@inbounds` in `fill!` for `Array` #59181 dropped `@inbounds` from `_fill!` for every `AbstractArray`. For an `Array`, `eachindex` is its own index range, so the check can never fail, and LLVM usually removes it, but not when the array of two or more dimensions was allocated in the same function (`zero`, `similar` followed by `fill!`): there the loop bound is the product of the constructor's sizes while the check reloads `size[1]` from the new array, and the two are only unified by GVN, after IndVarSimplify, the pass that would drop the check. With the check left, the loop cannot become a `memset`, which made `zero` of a matrix about twice as slow as `zeros` (#61870): | | before | after | |:--|--:|--:| | `zero(::Matrix{Float64})`, 1024×1024 | 59 µs | 29 µs | | `zero(::Array{Float64,3})`, 128×128×64 | 59 µs | 29 µs | | `zero(::Matrix{Int32})`, 1024×1024 | 30 µs | 15 µs | | `zero(::Vector{Float64})`, 2^20 | 29 µs | 29 µs | (Apple M4 Pro.) Other `AbstractArray`s keep the checked loop. #61873 closed #61870 by running `LoopIdiomRecognizePass` before IndVarSimplify, which fixed filling an *existing* matrix (its benchmark), but not the issue's `zero(A)`, where the allocation precedes the loop: that is still 2x slower than `zeros` on master. Fixes #61870 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Committer
Parents
Loading