Skip to content

Commit 4261ac8

Browse files
committed
inline and add test case
1 parent 3120724 commit 4261ac8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ broadcast_unalias(::Nothing, src) = src
870870
preprocess(f, dest, x) = f(broadcast_unalias(dest, x))
871871

872872
@inline preprocess_args(f, dest, args::Tuple) = (preprocess(f, dest, args[1]), preprocess_args(f, dest, tail(args))...)
873-
preprocess_args(f, dest, args::Tuple{Any}) = (preprocess(f, dest, args[1]),)
873+
@inline preprocess_args(f, dest, args::Tuple{Any}) = (preprocess(f, dest, args[1]),)
874874
preprocess_args(f, dest, args::Tuple{}) = ()
875875

876876
# Specialize this method if all you want to do is specialize on typeof(dest)

test/broadcast.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,17 @@ let
790790
@test Dict(c .=> d) == Dict("foo" => 1, "bar" => 2)
791791
end
792792

793+
@testset "large fusions vectorize and don't allocate (#28126)" begin
794+
u, k1, k2, k3, k4, k5, k6, k7 = (ones(1000) for i in 1:8)
795+
function goo(u, k1, k2, k3, k4, k5, k6, k7)
796+
@. u = 0.1*(0.1*k1 + 0.2*k2 + 0.3*k3 + 0.4*k4 + 0.5*k5 + 0.6*k6 + 0.7*k7)
797+
nothing
798+
end
799+
@allocated goo(u, k1, k2, k3, k4, k5, k6, k7)
800+
@test @allocated(goo(u, k1, k2, k3, k4, k5, k6, k7)) == 0
801+
@test occursin("vector.body", sprint(code_llvm, goo, NTuple{8, Vector{Float32}}))
802+
end
803+
793804
# Broadcasted iterable/indexable APIs
794805
let
795806
bc = Broadcast.instantiate(Broadcast.broadcasted(+, zeros(5), 5))

0 commit comments

Comments
 (0)