Skip to content

Commit ac3d8d9

Browse files
Merge pull request #733 from AayushSabharwal/as/cse-fixes
fix: fix some issues with CSE
2 parents 715026d + 27ccab9 commit ac3d8d9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/code.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ function cse!(expr::Symbolic, state::CSEState)
857857
args = arguments(expr)
858858
cse_inside_expr(expr, op, args...) || return expr
859859
args = map(args) do arg
860-
if arg isa Union{Tuple, AbstractArray}
860+
if arg isa Union{Tuple, AbstractArray} &&
861+
(_is_array_of_symbolics(arg) || _is_tuple_of_symbolics(arg))
861862
if arg isa Tuple
862863
new_arg = cse!(MakeTuple(arg), state)
863864
sym = newsym(Tuple{symtype.(arg)...})
@@ -889,6 +890,7 @@ cse!(x::LiteralExpr, ::CSEState) = x
889890

890891
cse!(x::CodegenPrimitive, state::CSEState) = throw(MethodError(cse!, (x, state)))
891892

893+
cse!(x::AbstractRange, ::CSEState) = x
892894
function cse!(x::AbstractArray, state::CSEState)
893895
res = map(Base.Fix2(cse!, state), x)
894896
return res

test/cse.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,12 @@ end
220220
@test all(iszero, arr[1:3])
221221
@test all(iszero, arr[8:end])
222222
end
223+
224+
@testset "CSE doesn't affect ranges" begin
225+
@syms x::Array
226+
t = term(view, x, 1:3)
227+
fnexpr = Func([x], [], t)
228+
fn1 = @RuntimeGeneratedFunction(toexpr(fnexpr))
229+
fn2 = @RuntimeGeneratedFunction(cse(toexpr(fnexpr)))
230+
@test fn1(ones(5)) == fn2(ones(5))
231+
end

0 commit comments

Comments
 (0)