Skip to content

Commit b16463c

Browse files
committed
cmd/compile: in prove, give a different name to each poset
Instead of using a two-slot array and having to remember which index is the signed poset, and which is the unsigned one, just use two different variables. Change-Id: Ic7f7676436c51bf43a182e999a926f8b7f69434b Reviewed-on: https://go-review.googlesource.com/c/go/+/196678 Reviewed-by: Keith Randall <[email protected]>
1 parent e4c3925 commit b16463c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/cmd/compile/internal/ssa/prove.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ type factsTable struct {
164164
// order is a couple of partial order sets that record information
165165
// about relations between SSA values in the signed and unsigned
166166
// domain.
167-
order [2]*poset
167+
orderS *poset
168+
orderU *poset
168169

169170
// known lower and upper bounds on individual values.
170171
limits map[ID]limit
@@ -187,10 +188,10 @@ var checkpointBound = limitFact{}
187188

188189
func newFactsTable(f *Func) *factsTable {
189190
ft := &factsTable{}
190-
ft.order[0] = f.newPoset() // signed
191-
ft.order[1] = f.newPoset() // unsigned
192-
ft.order[0].SetUnsigned(false)
193-
ft.order[1].SetUnsigned(true)
191+
ft.orderS = f.newPoset()
192+
ft.orderU = f.newPoset()
193+
ft.orderS.SetUnsigned(false)
194+
ft.orderU.SetUnsigned(true)
194195
ft.facts = make(map[pair]relation)
195196
ft.stack = make([]fact, 4)
196197
ft.limits = make(map[ID]limit)
@@ -221,23 +222,23 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) {
221222

222223
if d == signed || d == unsigned {
223224
var ok bool
224-
idx := 0
225+
order := ft.orderS
225226
if d == unsigned {
226-
idx = 1
227+
order = ft.orderU
227228
}
228229
switch r {
229230
case lt:
230-
ok = ft.order[idx].SetOrder(v, w)
231+
ok = order.SetOrder(v, w)
231232
case gt:
232-
ok = ft.order[idx].SetOrder(w, v)
233+
ok = order.SetOrder(w, v)
233234
case lt | eq:
234-
ok = ft.order[idx].SetOrderOrEqual(v, w)
235+
ok = order.SetOrderOrEqual(v, w)
235236
case gt | eq:
236-
ok = ft.order[idx].SetOrderOrEqual(w, v)
237+
ok = order.SetOrderOrEqual(w, v)
237238
case eq:
238-
ok = ft.order[idx].SetEqual(v, w)
239+
ok = order.SetEqual(v, w)
239240
case lt | gt:
240-
ok = ft.order[idx].SetNonEqual(v, w)
241+
ok = order.SetNonEqual(v, w)
241242
default:
242243
panic("unknown relation")
243244
}
@@ -588,6 +589,7 @@ func (ft *factsTable) isNonNegative(v *Value) bool {
588589
}
589590

590591
// Check if the recorded limits can prove that the value is positive
592+
591593
if l, has := ft.limits[v.ID]; has && (l.min >= 0 || l.umax <= uint64(max)) {
592594
return true
593595
}
@@ -610,7 +612,7 @@ func (ft *factsTable) isNonNegative(v *Value) bool {
610612
}
611613

612614
// Check if the signed poset can prove that the value is >= 0
613-
return ft.order[0].OrderedOrEqual(ft.zero, v)
615+
return ft.orderS.OrderedOrEqual(ft.zero, v)
614616
}
615617

616618
// checkpoint saves the current state of known relations.
@@ -621,8 +623,8 @@ func (ft *factsTable) checkpoint() {
621623
}
622624
ft.stack = append(ft.stack, checkpointFact)
623625
ft.limitStack = append(ft.limitStack, checkpointBound)
624-
ft.order[0].Checkpoint()
625-
ft.order[1].Checkpoint()
626+
ft.orderS.Checkpoint()
627+
ft.orderU.Checkpoint()
626628
}
627629

628630
// restore restores known relation to the state just
@@ -658,8 +660,8 @@ func (ft *factsTable) restore() {
658660
ft.limits[old.vid] = old.limit
659661
}
660662
}
661-
ft.order[0].Undo()
662-
ft.order[1].Undo()
663+
ft.orderS.Undo()
664+
ft.orderU.Undo()
663665
}
664666

665667
func lessByID(v, w *Value) bool {
@@ -922,7 +924,7 @@ func prove(f *Func) {
922924
ft.restore()
923925

924926
// Return the posets to the free list
925-
for _, po := range ft.order {
927+
for _, po := range []*poset{ft.orderS, ft.orderU} {
926928
// Make sure it's empty as it should be. A non-empty poset
927929
// might cause errors and miscompilations if reused.
928930
if checkEnabled {

0 commit comments

Comments
 (0)