1
0
mirror of https://github.com/golang/go synced 2024-09-30 01:14:29 -06:00

cmd/compile: move statement marks from jumps to targets

When a jump at the end of a block is about to be marked as
a statement, if the first real instruction in the target
block is also a statement for the same line, remove the
mark from the jump.

This is a first effort at a minimal-harm heuristic.
A better heuristic might skip over any "not-statement"
values preceding a definitely marked value.

Fixes #29443.

Change-Id: Ibd52783713b4936e0c2dfda8d708bf186f33b00a
Reviewed-on: https://go-review.googlesource.com/c/go/+/159977
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
David Chase 2019-01-28 18:00:01 -05:00
parent bd680d94a0
commit 82af9e6749
2 changed files with 13 additions and 0 deletions

View File

@ -5236,7 +5236,10 @@ func genssa(f *ssa.Func, pp *Progs) {
br.P.To.Val = s.bstart[br.B.ID]
if br.P.Pos.IsStmt() != src.PosIsStmt {
br.P.Pos = br.P.Pos.WithNotStmt()
} else if v0 := br.B.FirstPossibleStmtValue(); v0 != nil && v0.Pos.Line() == br.P.Pos.Line() && v0.Pos.IsStmt() == src.PosIsStmt {
br.P.Pos = br.P.Pos.WithNotStmt()
}
}
if e.log { // spew to stdout

View File

@ -73,6 +73,16 @@ func notStmtBoundary(op Op) bool {
return false
}
func (b *Block) FirstPossibleStmtValue() *Value {
for _, v := range b.Values {
if notStmtBoundary(v.Op) {
continue
}
return v
}
return nil
}
func numberLines(f *Func) {
po := f.Postorder()
endlines := make(map[ID]src.XPos)