Commit c8e7c53b authored by David Chase's avatar David Chase

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 <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJeremy Faller <jeremy@golang.org>
parent 33ab6ccb
...@@ -266,6 +266,7 @@ func (v *Value) reset(op Op) { ...@@ -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. // 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 { 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 := b.NewValue0(v.Pos.WithNotStmt(), v.Op, v.Type) // Lose the position, this causes line number churn otherwise.
c.Aux = v.Aux c.Aux = v.Aux
...@@ -281,7 +282,14 @@ func (v *Value) copyInto(b *Block) *Value { ...@@ -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. // 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. // 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 { 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 := b.NewValue0(pos, v.Op, v.Type)
c.Aux = v.Aux c.Aux = v.Aux
c.AuxInt = v.AuxInt c.AuxInt = v.AuxInt
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment