mirror of
https://github.com/golang/go
synced 2024-11-24 15:40:09 -07:00
[dev.ssa] cmd/compile/internal/ssa: replace load of store with a copy
This is a AMD64 version of CL19743. Saves additional 1574 bytes in go binary. This also speeds up bzip2 by 1-4% Change-Id: I031ba423663c4e83fdefe44e5296f24143e303da Reviewed-on: https://go-review.googlesource.com/19939 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
1b1d0a9a80
commit
5c5fa3628c
@ -608,6 +608,12 @@
|
||||
(MOVLQSX (MOVLload [off] {sym} ptr mem)) -> @v.Args[0].Block (MOVLQSXload <v.Type> [off] {sym} ptr mem)
|
||||
(MOVLQZX (MOVLload [off] {sym} ptr mem)) -> @v.Args[0].Block (MOVLQZXload <v.Type> [off] {sym} ptr mem)
|
||||
|
||||
// replace load from same location as preceding store with copy
|
||||
(MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
|
||||
(MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
|
||||
(MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
|
||||
(MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
|
||||
|
||||
// Fold extensions and ANDs together.
|
||||
(MOVBQZX (ANDBconst [c] x)) -> (ANDQconst [c & 0xff] x)
|
||||
(MOVWQZX (ANDWconst [c] x)) -> (ANDQconst [c & 0xffff] x)
|
||||
|
@ -5459,6 +5459,28 @@ func rewriteValueAMD64_OpAMD64MOVBQZX(v *Value, config *Config) bool {
|
||||
func rewriteValueAMD64_OpAMD64MOVBload(v *Value, config *Config) bool {
|
||||
b := v.Block
|
||||
_ = b
|
||||
// match: (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _))
|
||||
// cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)
|
||||
// result: x
|
||||
for {
|
||||
off := v.AuxInt
|
||||
sym := v.Aux
|
||||
ptr := v.Args[0]
|
||||
if v.Args[1].Op != OpAMD64MOVBstore {
|
||||
break
|
||||
}
|
||||
off2 := v.Args[1].AuxInt
|
||||
sym2 := v.Args[1].Aux
|
||||
ptr2 := v.Args[1].Args[0]
|
||||
x := v.Args[1].Args[1]
|
||||
if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) {
|
||||
break
|
||||
}
|
||||
v.reset(OpCopy)
|
||||
v.Type = x.Type
|
||||
v.AddArg(x)
|
||||
return true
|
||||
}
|
||||
// match: (MOVBload [off1] {sym} (ADDQconst [off2] ptr) mem)
|
||||
// cond:
|
||||
// result: (MOVBload [addOff(off1, off2)] {sym} ptr mem)
|
||||
@ -6042,6 +6064,28 @@ func rewriteValueAMD64_OpAMD64MOVLQZX(v *Value, config *Config) bool {
|
||||
func rewriteValueAMD64_OpAMD64MOVLload(v *Value, config *Config) bool {
|
||||
b := v.Block
|
||||
_ = b
|
||||
// match: (MOVLload [off] {sym} ptr (MOVLstore [off2] {sym2} ptr2 x _))
|
||||
// cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)
|
||||
// result: x
|
||||
for {
|
||||
off := v.AuxInt
|
||||
sym := v.Aux
|
||||
ptr := v.Args[0]
|
||||
if v.Args[1].Op != OpAMD64MOVLstore {
|
||||
break
|
||||
}
|
||||
off2 := v.Args[1].AuxInt
|
||||
sym2 := v.Args[1].Aux
|
||||
ptr2 := v.Args[1].Args[0]
|
||||
x := v.Args[1].Args[1]
|
||||
if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) {
|
||||
break
|
||||
}
|
||||
v.reset(OpCopy)
|
||||
v.Type = x.Type
|
||||
v.AddArg(x)
|
||||
return true
|
||||
}
|
||||
// match: (MOVLload [off1] {sym} (ADDQconst [off2] ptr) mem)
|
||||
// cond:
|
||||
// result: (MOVLload [addOff(off1, off2)] {sym} ptr mem)
|
||||
@ -6572,6 +6616,28 @@ func rewriteValueAMD64_OpAMD64MOVOstore(v *Value, config *Config) bool {
|
||||
func rewriteValueAMD64_OpAMD64MOVQload(v *Value, config *Config) bool {
|
||||
b := v.Block
|
||||
_ = b
|
||||
// match: (MOVQload [off] {sym} ptr (MOVQstore [off2] {sym2} ptr2 x _))
|
||||
// cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)
|
||||
// result: x
|
||||
for {
|
||||
off := v.AuxInt
|
||||
sym := v.Aux
|
||||
ptr := v.Args[0]
|
||||
if v.Args[1].Op != OpAMD64MOVQstore {
|
||||
break
|
||||
}
|
||||
off2 := v.Args[1].AuxInt
|
||||
sym2 := v.Args[1].Aux
|
||||
ptr2 := v.Args[1].Args[0]
|
||||
x := v.Args[1].Args[1]
|
||||
if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) {
|
||||
break
|
||||
}
|
||||
v.reset(OpCopy)
|
||||
v.Type = x.Type
|
||||
v.AddArg(x)
|
||||
return true
|
||||
}
|
||||
// match: (MOVQload [off1] {sym} (ADDQconst [off2] ptr) mem)
|
||||
// cond:
|
||||
// result: (MOVQload [addOff(off1, off2)] {sym} ptr mem)
|
||||
@ -7543,6 +7609,28 @@ func rewriteValueAMD64_OpAMD64MOVWQZX(v *Value, config *Config) bool {
|
||||
func rewriteValueAMD64_OpAMD64MOVWload(v *Value, config *Config) bool {
|
||||
b := v.Block
|
||||
_ = b
|
||||
// match: (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _))
|
||||
// cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)
|
||||
// result: x
|
||||
for {
|
||||
off := v.AuxInt
|
||||
sym := v.Aux
|
||||
ptr := v.Args[0]
|
||||
if v.Args[1].Op != OpAMD64MOVWstore {
|
||||
break
|
||||
}
|
||||
off2 := v.Args[1].AuxInt
|
||||
sym2 := v.Args[1].Aux
|
||||
ptr2 := v.Args[1].Args[0]
|
||||
x := v.Args[1].Args[1]
|
||||
if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) {
|
||||
break
|
||||
}
|
||||
v.reset(OpCopy)
|
||||
v.Type = x.Type
|
||||
v.AddArg(x)
|
||||
return true
|
||||
}
|
||||
// match: (MOVWload [off1] {sym} (ADDQconst [off2] ptr) mem)
|
||||
// cond:
|
||||
// result: (MOVWload [addOff(off1, off2)] {sym} ptr mem)
|
||||
|
Loading…
Reference in New Issue
Block a user