mirror of
https://github.com/golang/go
synced 2024-11-19 12:14:42 -07:00
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: Todd Neal <todd@tneal.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
3294014ae1
commit
da1802f1df
@ -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)
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user