From 8fe27b9014f16b356e09d0b108968402253fde90 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Mon, 22 May 2023 11:47:43 -0400 Subject: [PATCH] ignore `oftype` (#497) * ignore oftype * support expr in oftype disregard * change tests, storing in 0-dim arrays not supported --- Project.toml | 2 +- src/parse/add_compute.jl | 31 +++++++++++++++++++++++++++++++ test/miscellaneous.jl | 8 ++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 9cecc58a0..289020159 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LoopVectorization" uuid = "bdcacae8-1622-11e9-2a5c-532679323890" authors = ["Chris Elrod "] -version = "0.12.159" +version = "0.12.160" [deps] ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" diff --git a/src/parse/add_compute.jl b/src/parse/add_compute.jl index 20176c1e9..2427ecdf4 100644 --- a/src/parse/add_compute.jl +++ b/src/parse/add_compute.jl @@ -475,6 +475,7 @@ function add_compute!( return add_anon_func!(ls, var, fexpr, ex, position, mpref, elementbytes) # instr = instruction(first(ex.args))::Symbol instr = instruction!(ls, first(ex.args))::Instruction + args = @view(ex.args[2:end]) if (instr.instr === :pow_fast || instr.instr === :(^)) && length(args) == 2 arg1 = args[1] @@ -495,6 +496,8 @@ function add_compute!( arg2num = Int(static(ex.args[3]))::Int return add_pow!(ls, var, args[1], arg2num, elementbytes, position) end + elseif instr.instr === :oftype && length(args) == 2 + return get_arg!(ls, args[2], elementbytes, position) end vparents = Operation[] deps = Symbol[] @@ -757,6 +760,34 @@ function add_compute_ifelse!( ) pushop!(ls, op, LHS) end +function get_arg!( + ls::LoopSet, + @nospecialize(x), + elementbytes::Int, + position::Int +)::Operation + if x isa Expr + add_operation!( + ls, + Symbol("###xpow###$(length(operations(ls)))###"), + x, + elementbytes, + position + )::Operation + elseif x isa Symbol + if x ∈ ls.loopsymbols + add_loopvalue!(ls, x, elementbytes) + else + xo = get(ls.opdict, x, nothing) + xo === nothing && return add_constant!(ls, x, elementbytes)::Operation + return xo + end + elseif x isa Number + return add_constant!(ls, x^p, elementbytes, var)::Operation + else + throw("objects of type $x not supported as arg") + end +end # adds x ^ (p::Real) function add_pow!( diff --git a/test/miscellaneous.jl b/test/miscellaneous.jl index c258097fe..ccd4738f5 100644 --- a/test/miscellaneous.jl +++ b/test/miscellaneous.jl @@ -1378,8 +1378,8 @@ end axkernel = axes(kernel, 1) zout = convert(eltype(out), z) for Ipost in Rpost - for i in axout_tile - @turbo for Ipre in Rpre + @turbo for i in axout_tile + for Ipre in Rpre tmp = zout # tmp = convert(eltype(out), z) # failing to hoist this leads to an "UndefVarError: tmp not defined" for j in axkernel @@ -1402,8 +1402,8 @@ end ) axkernel = axes(kernel, 1) for Ipost in Rpost - for i in axout_tile - @turbo for Ipre in Rpre + @turbo for i in axout_tile + for Ipre in Rpre tmp = zero(eltype(out)) # tmp = convert(eltype(out), z) # failing to hoist this leads to an "UndefVarError: tmp not defined" for j in axkernel