I think d ^ 2
should be optimized into just d * d
(here), so the following two operations should be identical, but the form with ^
allocates with the one with *
does not:
julia> using BenchmarkTools
julia> const a = rand(3); const b = rand(3); const c = rand(3); const d = rand(3);
julia> @btime @. $a = $b + $c * $d ^ 2;
23.668 ns (2 allocations: 16 bytes)
julia> @btime @. $a = $b + $c * $d * $d;
17.883 ns (0 allocations: 0 bytes)
Also if the $b +
is removed then there are no allocations
julia> @btime @. $a = $c * $d ^ 2;
8.064 ns (0 allocations: 0 bytes)
Is this a bug?