Commit da1802f1 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: use OffPtr when possible

OffPtr allocates less and is easier to optimize.

With this change, the OffPtr collapsing opt
rule matches increase from 160k to 263k,
and the Load-after-Store opt rule matches
increase from 217 to 853.

Change-Id: I763426a3196900f22a367f7f6d8e8047b279653d
Reviewed-on: https://go-review.googlesource.com/20273
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarTodd Neal <todd@tneal.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 3294014a
......@@ -1869,7 +1869,7 @@ func (s *state) expr(n *Node) *ssa.Value {
case ODOTPTR:
p := s.expr(n.Left)
s.nilCheck(p)
p = s.newValue2(ssa.OpAddPtr, p.Type, p, s.constInt(Types[TINT], n.Xoffset))
p = s.newValue1I(ssa.OpOffPtr, p.Type, n.Xoffset, p)
return s.newValue2(ssa.OpLoad, n.Type, p, s.mem())
case OINDEX:
......@@ -1884,7 +1884,11 @@ func (s *state) expr(n *Node) *ssa.Value {
}
ptrtyp := Ptrto(Types[TUINT8])
ptr := s.newValue1(ssa.OpStringPtr, ptrtyp, a)
ptr = s.newValue2(ssa.OpAddPtr, ptrtyp, ptr, i)
if Isconst(n.Right, CTINT) {
ptr = s.newValue1I(ssa.OpOffPtr, ptrtyp, n.Right.Int(), ptr)
} else {
ptr = s.newValue2(ssa.OpAddPtr, ptrtyp, ptr, i)
}
return s.newValue2(ssa.OpLoad, Types[TUINT8], ptr, s.mem())
case n.Left.Type.IsSlice():
p := s.addr(n, false)
......@@ -2526,17 +2530,16 @@ func (s *state) addr(n *Node, bounded bool) *ssa.Value {
return p
case ODOT:
p := s.addr(n.Left, bounded)
return s.newValue2(ssa.OpAddPtr, t, p, s.constInt(Types[TINT], n.Xoffset))
return s.newValue1I(ssa.OpOffPtr, t, n.Xoffset, p)
case ODOTPTR:
p := s.expr(n.Left)
if !bounded {
s.nilCheck(p)
}
return s.newValue2(ssa.OpAddPtr, t, p, s.constInt(Types[TINT], n.Xoffset))
return s.newValue1I(ssa.OpOffPtr, t, n.Xoffset, p)
case OCLOSUREVAR:
return s.newValue2(ssa.OpAddPtr, t,
s.entryNewValue0(ssa.OpGetClosurePtr, Ptrto(Types[TUINT8])),
s.constInt(Types[TINT], n.Xoffset))
return s.newValue1I(ssa.OpOffPtr, t, n.Xoffset,
s.entryNewValue0(ssa.OpGetClosurePtr, Ptrto(Types[TUINT8])))
case OPARAM:
p := n.Left
if p.Op != ONAME || !(p.Class == PPARAM|PHEAP || p.Class == PPARAMOUT|PHEAP) {
......
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