From: Keith Randall Date: Tue, 6 Jun 2017 22:25:29 +0000 (-0700) Subject: cmd/compile: check that phis are always first after scheduling X-Git-Tag: go1.9beta1~97 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a027466e4b6d594fd8b562094fe63a9c4c6ec4f7;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- diff --git a/src/cmd/compile/internal/ssa/check.go b/src/cmd/compile/internal/ssa/check.go index 82aa9f1ce8..17f683fb10 100644 --- a/src/cmd/compile/internal/ssa/check.go +++ b/src/cmd/compile/internal/ssa/check.go @@ -444,6 +444,22 @@ func memCheck(f *Func) { } } } + + // Check that after scheduling, phis are always first in the block. + if f.scheduled { + for _, b := range f.Blocks { + seenNonPhi := false + for _, v := range b.Values { + if v.Op == OpPhi { + if seenNonPhi { + f.Fatalf("phi after non-phi @ %s: %s", b, v) + } + } else { + seenNonPhi = true + } + } + } + } } // domCheck reports whether x dominates y (including x==y). diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go index bac4930e78..08a2c6df14 100644 --- a/src/cmd/compile/internal/ssa/deadstore.go +++ b/src/cmd/compile/internal/ssa/deadstore.go @@ -117,7 +117,11 @@ func dse(f *Func) { } // walk to previous store if v.Op == OpPhi { - continue // At start of block. Move on to next block. + // At start of block. Move on to next block. + // The memory phi, if it exists, is always + // the first logical store in the block. + // (Even if it isn't the first in the current b.Values order.) + continue } for _, a := range v.Args { if a.Block == b && a.Type.IsMemory() { diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 06595586c1..b42d53032c 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -211,6 +211,8 @@ search: } if v.Op == OpPhi { // A Phi implies we have reached the top of the block. + // The memory phi, if it exists, is always + // the first logical store in the block. continue search } if v.Type.IsTuple() && v.Type.FieldType(1).IsMemory() { @@ -228,6 +230,8 @@ search: const limit = 50 for i := 0; i < limit; i++ { if m.Op == OpPhi { + // The memory phi, if it exists, is always + // the first logical store in the block. break } if m.Block.ID != target.Block.ID {