Skip to content

Commit a027466

Browse files
committed
cmd/compile: check that phis are always first after scheduling
Update #20178 Change-Id: I603f77268ed38afdd84228c775efe006f08f14a7 Reviewed-on: https://go-review.googlesource.com/45018 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
1 parent f425f54 commit a027466

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,22 @@ func memCheck(f *Func) {
444444
}
445445
}
446446
}
447+
448+
// Check that after scheduling, phis are always first in the block.
449+
if f.scheduled {
450+
for _, b := range f.Blocks {
451+
seenNonPhi := false
452+
for _, v := range b.Values {
453+
if v.Op == OpPhi {
454+
if seenNonPhi {
455+
f.Fatalf("phi after non-phi @ %s: %s", b, v)
456+
}
457+
} else {
458+
seenNonPhi = true
459+
}
460+
}
461+
}
462+
}
447463
}
448464

449465
// domCheck reports whether x dominates y (including x==y).

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ func dse(f *Func) {
117117
}
118118
// walk to previous store
119119
if v.Op == OpPhi {
120-
continue // At start of block. Move on to next block.
120+
// At start of block. Move on to next block.
121+
// The memory phi, if it exists, is always
122+
// the first logical store in the block.
123+
// (Even if it isn't the first in the current b.Values order.)
124+
continue
121125
}
122126
for _, a := range v.Args {
123127
if a.Block == b && a.Type.IsMemory() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ search:
211211
}
212212
if v.Op == OpPhi {
213213
// A Phi implies we have reached the top of the block.
214+
// The memory phi, if it exists, is always
215+
// the first logical store in the block.
214216
continue search
215217
}
216218
if v.Type.IsTuple() && v.Type.FieldType(1).IsMemory() {
@@ -228,6 +230,8 @@ search:
228230
const limit = 50
229231
for i := 0; i < limit; i++ {
230232
if m.Op == OpPhi {
233+
// The memory phi, if it exists, is always
234+
// the first logical store in the block.
231235
break
232236
}
233237
if m.Block.ID != target.Block.ID {

0 commit comments

Comments
 (0)