You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cmd/compile/internal/ssa/deadstore.go
+14-19Lines changed: 14 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -21,18 +21,21 @@ func dse(f *Func) {
21
21
deferf.retSparseSet(storeUse)
22
22
shadowed:=f.newSparseMap(f.NumValues())
23
23
deferf.retSparseMap(shadowed)
24
-
localAddrs:=f.newSparseSet(f.NumValues())
25
-
deferf.retSparseSet(localAddrs)
24
+
// localAddrs maps from a local variable (the Aux field of a LocalAddr value) to an instance of a LocalAddr value for that variable in the current block.
25
+
localAddrs:=map[any]*Value{}
26
26
for_, b:=rangef.Blocks {
27
27
// Find all the stores in this block. Categorize their uses:
28
28
// loadUse contains stores which are used by a subsequent load.
29
29
// storeUse contains stores which are used by a subsequent store.
30
30
// localAddrs contains indexes into b.Values for each unique LocalAddr.
31
31
loadUse.clear()
32
32
storeUse.clear()
33
-
localAddrs.clear()
33
+
// TODO(deparker): use the 'clear' builtin once compiler bootstrap minimum version is raised to 1.21.
34
+
fork:=rangelocalAddrs {
35
+
delete(localAddrs, k)
36
+
}
34
37
stores=stores[:0]
35
-
fori, v:=rangeb.Values {
38
+
for_, v:=rangeb.Values {
36
39
ifv.Op==OpPhi {
37
40
// Ignore phis - they will always be first and can't be eliminated
38
41
continue
@@ -51,10 +54,11 @@ func dse(f *Func) {
51
54
}
52
55
} else {
53
56
ifv.Op==OpLocalAddr {
54
-
iffindSameLocalAddr(b, v, localAddrs) >=0 {
57
+
if_, ok:=localAddrs[v.Aux]; !ok {
58
+
localAddrs[v.Aux] =v
59
+
} else {
55
60
continue
56
61
}
57
-
localAddrs.add(ID(i))
58
62
}
59
63
for_, a:=rangev.Args {
60
64
ifa.Block==b&&a.Type.IsMemory() {
@@ -110,9 +114,10 @@ func dse(f *Func) {
110
114
} else { // OpZero
111
115
sz=v.AuxInt
112
116
}
113
-
idx:=findSameLocalAddr(b, ptr, localAddrs)
114
-
ifidx!=-1 {
115
-
ptr=b.Values[idx]
117
+
ifptr.Op==OpLocalAddr {
118
+
ifla, ok:=localAddrs[ptr.Aux]; ok {
119
+
ptr=la
120
+
}
116
121
}
117
122
sr:=shadowRange(shadowed.get(ptr.ID))
118
123
ifsr.contains(off, off+sz) {
@@ -150,16 +155,6 @@ func dse(f *Func) {
150
155
}
151
156
}
152
157
153
-
funcfindSameLocalAddr(b*Block, vv*Value, localAddrs*sparseSet) int {
154
-
for_, idx:=rangelocalAddrs.contents() {
155
-
la:=b.Values[idx]
156
-
ifisSamePtr(la, vv) {
157
-
returnint(idx)
158
-
}
159
-
}
160
-
return-1
161
-
}
162
-
163
158
// A shadowRange encodes a set of byte offsets [lo():hi()] from
164
159
// a given pointer that will be written to later in the block.
165
160
// A zero shadowRange encodes an empty shadowed range (and so
0 commit comments