@@ -30,28 +30,25 @@ function add_store!(
30
30
ls:: LoopSet , var:: Symbol , mpref:: ArrayReferenceMetaPosition , elementbytes:: Int , parent = getop (ls, var, mpref. loopdependencies, elementbytes)
31
31
)
32
32
isload (parent) && return add_copystore! (ls, parent, mpref, elementbytes)
33
- parents = mpref. parents
33
+ vparents = mpref. parents
34
34
ldref = mpref. loopdependencies
35
35
reduceddeps = mpref. reduceddeps
36
36
pvar = name (parent)
37
37
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
47
46
end
48
- add_pvar = false
49
- else
50
- add_pvar = true
47
+ add_pvar &= (name (first (parents (opp))) != pvar)
51
48
end
52
- pushfirst! (parents , parent)
49
+ pushfirst! (vparents , parent)
53
50
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 )
55
52
add_store! (ls, op, add_pvar)
56
53
end
57
54
@@ -97,39 +94,42 @@ function add_conditional_store!(ls::LoopSet, LHS, condop::Operation, storeop::Op
97
94
98
95
pvar = storeop. variable
99
96
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
133
133
op = Operation ( id, name (mref), elementbytes, :conditionalstore! , memstore, ldref, NODEPENDENCY, storeparents, mref )
134
134
add_unique_store! (ls, op)
135
135
end
0 commit comments