Alias analysis sometimes too strict for SubArrays #54621
Closed
Description
Hi everyone,
I hit some very weird corner case where I create views on vectors where the index set is a vector. This causes some troubles for alias analysis. A minimal example which should be efficient to perform due to the shared index set is to copy the values from one subvector to another one.
using BenchmarkTools
indices = [1,3]
a = rand(3)
av = @view a[indices]
b = rand(3)
bv = @view b[indices]
@btime copyto!($av, $bv) # 2 allocations
av = @view a[[1,3]]
bv = @view b[[1,3]]
@btime copyto!($av, $bv) # 0 allocations
I discovered this on Julia 1.10, but from going down the call graph I also assume that it is reproducible with older versions too, because it can be tracked down to mightalias returning true for the first case.
Activity