Skip to content

Commit f588015

Browse files
committed
Added a test, fixed a bug.
1 parent cf37007 commit f588015

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/lower_compute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function lower_compute!(
255255
end
256256
if instr.instr === :identity && isone(length(parents_op))
257257
push!(q.args, Expr(:(=), varsym, instrcall.args[2]))
258-
elseif should_broadcast_op(op)
258+
elseif identifier(op) ls.outer_reductions && should_broadcast_op(op)
259259
push!(q.args, Expr(:(=), varsym, Expr(:call, lv(:vbroadcast), VECTORWIDTHSYMBOL, instrcall)))
260260
else
261261
push!(q.args, Expr(:(=), varsym, instrcall))

src/lower_constant.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
function should_broadcast_op(op::Operation)
3-
isvectorized(op) && return false
3+
(isvectorized(op) || iszero(length(children(op)))) && return false
44
for opc children(op)
55
(!isvectorized(op) || accesses_memory(op)) && return false
66
end

test/ifelsemasks.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,21 @@ T = Float32
346346
end
347347
res
348348
end
349-
349+
function testfunction!(f::Matrix{<:AbstractFloat}, v, d, g, s, θ)
350+
@inbounds @simd for j in 1:size(f,1)
351+
x = v[j, s] + v[j, d] - v[j, g] + f[j, g] + θ
352+
_x = ifelse(isnan(x), typemin(eltype(f)), x)
353+
f[j, d] = _x
354+
end
355+
end
356+
function testfunctionavx!(f::Matrix{<:AbstractFloat}, v, d, g, s, θ)
357+
@avx for j in 1:size(f,1)
358+
x = v[j, s] + v[j, d] - v[j, g] + f[j, g] + θ
359+
_x = ifelse(isnan(x), typemin(eltype(f)), x)
360+
f[j, d] = _x
361+
end
362+
end
363+
350364
N = 117
351365
for T (Float32, Float64, Int32, Int64)
352366
@show T, @__LINE__
@@ -503,4 +517,13 @@ T = Float32
503517
@test (a .& b) == (@avx a .& b)
504518
@test (a .| b) == (@avx a .| b)
505519
@test (a .⊻ b) == (@avx a .⊻ b)
520+
521+
s, d, g = 3, 1, 2; f = rand(N,2); v = rand(N,3); θ = 0.78;
522+
v[rand(eachindex(v), length(v) >> 3)] .= NaN;
523+
fc = copy(f);
524+
testfunction!(fc, v, d, g, s, θ);
525+
# fc2 = copy(f);
526+
testfunctionavx!(f, v, d, g, s, θ)
527+
@test f fc
528+
506529
end

0 commit comments

Comments
 (0)