From: David Chase Date: Mon, 30 Sep 2019 19:16:54 +0000 (-0400) Subject: cmd/compile: preserve statement mark in rematerialized values X-Git-Tag: go1.14beta1~867 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c8e7c53b40023c92c9d7fa6beb1ca4223bd461ae;p=gostls13.git cmd/compile: preserve statement mark in rematerialized values Statement markers on rematerializable values were getting lost in register allocation. This checks for that case (rematerializable input and using value share line number, but mark is on the input) and preserves the mark. When combined with other CLs in this series, this CL reduces the "nostmt" count (a line appears in the assembly, but no statement marker) for cmd/go from 413 to 277. The rematerialized input is usually a LEAQ (on AMD64). The cause is "complicated"; for example, a NilCheck originally has the statement mark (a good thing, if the NilCheck remains) but the NilCheck is removed and the mark floats to a Block end, then to a SliceMake. The SliceMake decomposes and goes dead without preserving its marker (its component values are elided in other rewrites and may target inputs with different line numbers), but before deadcode removes it from the graph it moves the mark to an input, which at that time happens to be a LocalAddr. This eventually transforms to a LEAQ. Change-Id: Iff91fc2a934357fb59ec46ac87b4a9b1057d9160 Reviewed-on: https://go-review.googlesource.com/c/go/+/198480 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- diff --git a/src/cmd/compile/internal/ssa/value.go b/src/cmd/compile/internal/ssa/value.go index d2038fcfa5..c08eba3d44 100644 --- a/src/cmd/compile/internal/ssa/value.go +++ b/src/cmd/compile/internal/ssa/value.go @@ -266,6 +266,7 @@ func (v *Value) reset(op Op) { } // copyInto makes a new value identical to v and adds it to the end of b. +// unlike copyIntoWithXPos this does not check for v.Pos being a statement. func (v *Value) copyInto(b *Block) *Value { c := b.NewValue0(v.Pos.WithNotStmt(), v.Op, v.Type) // Lose the position, this causes line number churn otherwise. c.Aux = v.Aux @@ -281,7 +282,14 @@ func (v *Value) copyInto(b *Block) *Value { // copyIntoWithXPos makes a new value identical to v and adds it to the end of b. // The supplied position is used as the position of the new value. +// Because this is used for rematerialization, check for case that (rematerialized) +// input to value with position 'pos' carried a statement mark, and that the supplied +// position (of the instruction using the rematerialized value) is not marked, and +// preserve that mark if its line matches the supplied position. func (v *Value) copyIntoWithXPos(b *Block, pos src.XPos) *Value { + if v.Pos.IsStmt() == src.PosIsStmt && pos.IsStmt() != src.PosIsStmt && v.Pos.SameFileAndLine(pos) { + pos = pos.WithIsStmt() + } c := b.NewValue0(pos, v.Op, v.Type) c.Aux = v.Aux c.AuxInt = v.AuxInt