From 82af9e67493b14ad1e10f28a384645e904a88d6f Mon Sep 17 00:00:00 2001 From: David Chase Date: Mon, 28 Jan 2019 18:00:01 -0500 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Alessandro Arzilli Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/ssa.go | 3 +++ src/cmd/compile/internal/ssa/numberlines.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index d6b2bd3137..ecc449114d 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -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 diff --git a/src/cmd/compile/internal/ssa/numberlines.go b/src/cmd/compile/internal/ssa/numberlines.go index 3e14b9e3df..ef5e133206 100644 --- a/src/cmd/compile/internal/ssa/numberlines.go +++ b/src/cmd/compile/internal/ssa/numberlines.go @@ -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)