Skip to content

Commit f00ef82

Browse files
committed
Commented out conditional store code which was broken; should fix later. Did fix store CSE code.
1 parent 791ce6a commit f00ef82

File tree

6 files changed

+70
-63
lines changed

6 files changed

+70
-63
lines changed

src/add_constants.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ end
4949
function add_constant!(
5050
ls::LoopSet, value::Symbol, deps::Vector{Symbol}, assignedsym::Symbol, elementbytes::Int, f::Symbol = Symbol("")
5151
)
52-
op = Operation(length(operations(ls)), assignedsym, elementbytes, Instruction(f, value), constant, deps, NODEPENDENCY, NOPARENTS)
52+
retop = get(ls.opdict, value, nothing)
53+
# @show retop, value ls.opdict
54+
if retop !== nothing
55+
op = Operation(length(operations(ls)), assignedsym, elementbytes, :identity, compute, deps, reduceddependencies(retop), [retop])
56+
else
57+
op = Operation(length(operations(ls)), assignedsym, elementbytes, Instruction(f, value), constant, deps, NODEPENDENCY, NOPARENTS)
58+
end
5359
pushop!(ls, op, assignedsym)
5460
end
5561
# function add_constant!(

src/add_stores.jl

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,25 @@ function add_store!(
3030
ls::LoopSet, var::Symbol, mpref::ArrayReferenceMetaPosition, elementbytes::Int, parent = getop(ls, var, mpref.loopdependencies, elementbytes)
3131
)
3232
isload(parent) && return add_copystore!(ls, parent, mpref, elementbytes)
33-
parents = mpref.parents
33+
vparents = mpref.parents
3434
ldref = mpref.loopdependencies
3535
reduceddeps = mpref.reduceddeps
3636
pvar = name(parent)
3737
id = length(ls.operations)
38-
if pvar ls.syms_aliasing_refs
39-
# try to cse store, by replacing the previous one
40-
ref = mpref.mref.ref
41-
for opp operations(ls)
42-
isstore(opp) || continue
43-
if ref == opp.ref.ref
44-
id = opp.identifier
45-
break
46-
end
38+
# try to cse store, by replacing the previous one
39+
ref = mpref.mref.ref
40+
add_pvar = true
41+
for opp operations(ls)
42+
isstore(opp) || continue
43+
if ref == opp.ref.ref
44+
id = opp.identifier
45+
break
4746
end
48-
add_pvar = false
49-
else
50-
add_pvar = true
47+
add_pvar &= (name(first(parents(opp))) != pvar)
5148
end
52-
pushfirst!(parents, parent)
49+
pushfirst!(vparents, parent)
5350
update_deps!(ldref, reduceddeps, parent)
54-
op = Operation( id, name(mpref), elementbytes, :setindex!, memstore, mpref )#loopdependencies, reduceddeps, parents, mpref.mref )
51+
op = Operation( id, name(mpref), elementbytes, :setindex!, memstore, mpref )
5552
add_store!(ls, op, add_pvar)
5653
end
5754

@@ -97,39 +94,42 @@ function add_conditional_store!(ls::LoopSet, LHS, condop::Operation, storeop::Op
9794

9895
pvar = storeop.variable
9996
id = length(ls.operations)
100-
if pvar ls.syms_aliasing_refs
101-
push!(ls.syms_aliasing_refs, pvar)
102-
push!(ls.refs_aliasing_syms, mref)
103-
storeparents = [storeop, condop]
104-
else
105-
# for now, we don't try to cse the store
106-
# later, as an optimization, we could:
107-
# 1. cse the store
108-
# 2. use the mask to combine the vector we're trying to store here with the vector that would have been stored in the now cse-ed 1.
109-
# 3. use a regular (non-masked) store on that vector.
110-
ref = mpref.mref.ref
111-
for opp operations(ls)
112-
isstore(opp) || continue
113-
if ref == opp.ref.ref# && return cse_store!(ls, identifier(opp), mref, parents, ldref, reduceddeps, elementbytes)
114-
id = opp.identifier
115-
break
116-
end
117-
end
118-
if id != length(ls.operations) # then there was a previous store
119-
prevstore = getop(ls, id + 1)
120-
storeop = add_compute!(ls, gensym(:combinedstoreop), Instruction(:vifelse), [condop, storeop, first(parents(prevstore))], elementbytes)
121-
storeparents = [storeop]
122-
storeinstr = if prevstore.instruction.instr === :conditionalstore!
123-
push!(storeparents, add_compute!(ls, gensym(:combinedmask), Instruction(:|), [condop, last(parents(prevstore))], elementbytes))
124-
:conditionalstore!
125-
else
126-
:setindex!
127-
end
128-
op = Operation( id, name(mref), elementbytes, storeinstr, memstore, ldref, NODEPENDENCY, storeparents, mref )
129-
cse_store!(ls, op)
130-
end
131-
end
132-
97+
@assert pvar ls.syms_aliasing_refs
98+
# if pvar ∉ ls.syms_aliasing_refs
99+
# FIXME properly handle CSE of conditional stores.
100+
push!(ls.syms_aliasing_refs, pvar)
101+
push!(ls.refs_aliasing_syms, mref)
102+
storeparents = [storeop, condop]
103+
# else
104+
# # for now, we don't try to cse the store
105+
# # later, as an optimization, we could:
106+
# # 1. cse the store
107+
# # 2. use the mask to combine the vector we're trying to store here with the vector that would have been stored in the now cse-ed 1.
108+
# # 3. use a regular (non-masked) store on that vector.
109+
# ref = mpref.mref.ref
110+
# for opp ∈ operations(ls)
111+
# isstore(opp) || continue
112+
# if ref == opp.ref.ref# && return cse_store!(ls, identifier(opp), mref, parents, ldref, reduceddeps, elementbytes)
113+
# id = opp.identifier
114+
# break
115+
# end
116+
# end
117+
# if id != length(ls.operations) # then there was a previous store
118+
# prevstore = getop(ls, id + 1)
119+
# # @show prevstore prevstore.node_type, loopdependencies(prevstore)
120+
# # @show operations(ls)
121+
# storeop = add_compute!(ls, gensym(:combinedstoreop), Instruction(:vifelse), [condop, storeop, first(parents(prevstore))], elementbytes)
122+
# storeparents = [storeop]
123+
# storeinstr = if prevstore.instruction.instr === :conditionalstore!
124+
# push!(storeparents, add_compute!(ls, gensym(:combinedmask), Instruction(:|), [condop, last(parents(prevstore))], elementbytes))
125+
# :conditionalstore!
126+
# else
127+
# :setindex!
128+
# end
129+
# op = Operation( id, name(mref), elementbytes, storeinstr, memstore, ldref, NODEPENDENCY, storeparents, mref )
130+
# return cse_store!(ls, op)
131+
# end
132+
# end
133133
op = Operation( id, name(mref), elementbytes, :conditionalstore!, memstore, ldref, NODEPENDENCY, storeparents, mref )
134134
add_unique_store!(ls, op)
135135
end

src/costs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ function Base.Expr(instr::Instruction, args...)
2222
end
2323
end
2424
Base.hash(instr::Instruction, h::UInt64) = hash(instr.instr, hash(instr.mod, h))
25-
function Base.isless(instr1::Instruction, instr2::Instruction)
26-
if instr1.mod === instr2.mod
27-
isless(instr1.instr, instr2.instr)
28-
else
29-
isless(instr1.mod, instr2.mod)
30-
end
31-
end
25+
# function Base.isless(instr1::Instruction, instr2::Instruction)
26+
# if instr1.mod === instr2.mod
27+
# isless(instr1.instr, instr2.instr)
28+
# else
29+
# isless(instr1.mod, instr2.mod)
30+
# end
31+
# end
3232
Base.isequal(ins1::Instruction, ins2::Instruction) = (ins1.instr === ins2.instr) && (ins1.mod === ins2.mod)
3333

3434
const LOOPCONSTANT = Instruction(gensym())

test/ifelsemasks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@
109109
x1 = 2*x[i]-100
110110
x2 = x1*x1
111111
x3 = x2 + x1
112+
x4 = x3
112113
x[i] = x1
113114
(x1 < -50) && (x[i] = x2)
114-
(x1 < 60) || (x[i] = x3)
115+
(x1 < 60) || (x[i] = x4)
115116
end
116117
end
117118
function condstoreavx!(x)
@@ -135,7 +136,6 @@
135136
end
136137
end
137138

138-
139139
N = 117
140140
for T (Float32, Float64, Int32, Int64)
141141
@show T, @__LINE__

test/printmethods.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@testset "Print Methods" begin
2-
selfdotq = :(for i eachindex(a)
2+
@show @__LINE__
3+
selfdotq = :(for i eachindex(a)
34
s += a[i]*a[i]
45
end)
56
lsselfdot = LoopVectorization.LoopSet(selfdotq);
@@ -9,6 +10,4 @@
910
@test occursin("Operation[", s)
1011
@test occursin("s = 0", s)
1112
@test occursin("s = LoopVectorization.vfmadd", s)
12-
13-
1413
end

test/runtests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function clenshaw(x,coeff)
1515
end
1616

1717
@time @testset "LoopVectorization.jl" begin
18-
19-
@time include("gemm.jl")
2018

19+
@time include("printmethods.jl")
20+
2121
@time include("dot.jl")
2222

2323
@time include("special.jl")
@@ -38,4 +38,6 @@ end
3838
@time include("filter.jl")
3939
end
4040

41+
@time include("gemm.jl")
42+
4143
end

0 commit comments

Comments
 (0)