Skip to content

Commit 559d78b

Browse files
Fix reciprocal of infinity in turbo loops
1 parent 369cebc commit 559d78b

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/parse/add_compute.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ function add_compute!(
498498
end
499499
elseif instr.instr === :oftype && length(args) == 2
500500
return get_arg!(ls, args[2], elementbytes, position)
501+
elseif instr.instr === :div_fast && length(args) == 2 && args[1] === 1
502+
return add_compute!(ls, var, :inv, [get_arg!(ls, args[2], elementbytes, position)], elementbytes)
501503
end
502504
vparents = Operation[]
503505
deps = Symbol[]
@@ -783,7 +785,7 @@ function get_arg!(
783785
return xo
784786
end
785787
elseif x isa Number
786-
return add_constant!(ls, x^p, elementbytes, var)::Operation
788+
return add_constant!(ls, x, elementbytes)::Operation
787789
else
788790
throw("objects of type $x not supported as arg")
789791
end

test/simplemisc.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ function issue480(x, y)
3333
end
3434
z
3535
end
36+
37+
function issue539!(y, x)
38+
@turbo for i in eachindex(x)
39+
y[i] = 1 / x[i]
40+
end
41+
y
42+
end
3643
@testset "issue 480" begin
3744
using LoopVectorization
3845
x = zeros(33)
@@ -44,3 +51,9 @@ end
4451
x[i] = 0.0
4552
end
4653
end
54+
55+
@testset "issue 539" begin
56+
x = fill(Inf, 32)
57+
y = similar(x)
58+
@test all(iszero, issue539!(y, x))
59+
end

0 commit comments

Comments
 (0)