Strange allocations in broadcasting (with `^`?)

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?

Looks similar to the issue noted in Memory allocation inconsistency in broadcasting · Issue #41565 · JuliaLang/julia · GitHub.

Thanks @kristoffer.carlsson! It does look like the same issue, and goes away with the latest master. Does anyone know if the fix will make it into julia-1.7? I do still get allocations with this example using 1.70-rc3, but they are gone if I use the current master (Version 1.8.0-DEV.1081 (2021-11-29) Commit 43bc48b1f8 (0 days old master).

Looks like the answer was no, at least for 1.7.0. The allocations are still there on the version released today.

julia> @btime @. $a = $b + $c * $d ^ 2;
  25.734 ns (2 allocations: 16 bytes)