Skip to content

Commit

Permalink
Get rid of more unneeded branches when loops are static.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Jul 15, 2020
1 parent a9d6014 commit 88e96c9
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,41 +277,46 @@ function lower_no_unroll(ls::LoopSet, us::UnrollSpecification, n::Int, inclmask:
tc = terminatecondition(ls, us, n, inclmask, 1)
body = lower_block(ls, us, n, inclmask, 1)
# align_loop = isone(n) & (ls.align_loops[] > 0)
isstatic = isstaticloop(loop)# & (!align_loop)
if !isstatic && (usorig.u₁ == us.u₁) && (usorig.u₂ == us.u₂) && !inclmask
loopisstatic = isstaticloop(loop)
if !loopisstatic && (usorig.u₁ == us.u₁) && (usorig.u₂ == us.u₂) && !inclmask
tc = expect(tc)
end
W = nisvectorized ? ls.vector_width[] : 1
loopisstatic &= (!iszero(W))
# q = if align_loop
# Expr(:block, align_inner_loop_expr(ls, us, loop), Expr(:while, tc, body))
# elseif nisvectorized
q = if nisvectorized
if loopisstatic && length(loop) 8W
q = Expr(:block)
foreach(_ -> push!(q.args, body), 1:(length(loop) ÷ W))
elseif nisvectorized
# Expr(:block, loopiteratesatleastonce(loop, true), Expr(:while, expect(tc), body))
Expr(:block, Expr(:while, tc, body))
elseif isstatic && length(loop) 8
bodyq = Expr(:block)
foreach(_ -> push!(bodyq.args, body), 1:length(loop))
bodyq
q = Expr(:block, Expr(:while, tc, body))
else
termcond = gensym(:maybeterm)
push!(body.args, Expr(:(=), termcond, tc))
Expr(:block, Expr(:(=), termcond, true), Expr(:while, termcond, body))
q = Expr(:block, Expr(:(=), termcond, true), Expr(:while, termcond, body))
# Expr(:block, Expr(:while, expect(tc), body))
# Expr(:block, assume(tc), Expr(:while, tc, body))
# push!(body.args, Expr(:&&, expect(Expr(:call, :!, tc)), Expr(:break)))
# Expr(:block, assume(tc), Expr(:while, true, body))
# push!(body.args, Expr(:||, expect(tc), Expr(:break)))
# Expr(:block, Expr(:while, true, body))
end
if nisvectorized
if nisvectorized && !(loopisstatic && iszero(length(loop) & (W - 1)))
# tc = terminatecondition(loop, us, n, loopsym, true, 1)
tc = terminatecondition(ls, us, n, true, 1)
body = lower_block(ls, us, n, true, 1)
if isone(num_loops(ls))
pushfirst!(body.args, definemask(loop))
# elseif align_loop
# pushfirst!(body.args, definemask_for_alignment_cleanup(loop))
end
push!(q.args, Expr(:if, tc, body))
if loopisstatic
push!(q.args, body)
else
tc = terminatecondition(ls, us, n, true, 1)
push!(q.args, Expr(:if, tc, body))
end
end
Expr(:block, Expr(:let, sl, q))
end
Expand Down Expand Up @@ -353,6 +358,7 @@ function lower_unrolled_dynamic(ls::LoopSet, us::UnrollSpecification, n::Int, in
remblock = init_remblock(loop, ls.lssm[], n)#loopsym)
q = Expr(:while, tc, body)
end
# @show loopsym, loopisstatic, UFW
q = if unsigned(Ureduct) < unsigned(UF) # unsigned(-1) == typemax(UInt); is logic relying on twos-complement bad?
UF_cleanup = UF - Ureduct
us_cleanup = nisunrolled ? UnrollSpecification(us, UF_cleanup, u₂) : UnrollSpecification(us, u₁, UF_cleanup)
Expand Down

2 comments on commit 88e96c9

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/17954

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.17 -m "<description of version>" 88e96c926c4c568b6cf3530d740ee55bdfc32aa8
git push origin v0.8.17

Please sign in to comment.