]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: preserve statement mark in rematerialized values
authorDavid Chase <drchase@google.com>
Mon, 30 Sep 2019 19:16:54 +0000 (15:16 -0400)
committerDavid Chase <drchase@google.com>
Fri, 4 Oct 2019 17:09:10 +0000 (17:09 +0000)
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 <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/compile/internal/ssa/value.go

index d2038fcfa59a9087523c777a684164183c98af01..c08eba3d4467aa919809899668666b9f316a73eb 100644 (file)
@@ -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