mirror of
https://github.com/golang/go
synced 2024-10-05 18:21:21 -06:00
[dev.ssa] cmd/compile/ssa: eliminate Zero with dse
Consider OpZero to be a store so it can be eliminated by dse. Change-Id: Idebb6a190657b76966f0c5b20f2ec9f52fe47499 Reviewed-on: https://go-review.googlesource.com/13447 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
463858e6ff
commit
dee1f2750b
@ -30,7 +30,7 @@ func dse(f *Func) {
|
||||
for _, a := range v.Args {
|
||||
if a.Block == b && a.Type.IsMemory() {
|
||||
storeUse.add(a.ID)
|
||||
if v.Op != OpStore {
|
||||
if v.Op != OpStore && v.Op != OpZero {
|
||||
// CALL, DUFFCOPY, etc. are both
|
||||
// reads and writes.
|
||||
loadUse.add(a.ID)
|
||||
@ -77,12 +77,24 @@ func dse(f *Func) {
|
||||
// Clear all shadowed addresses.
|
||||
shadowed.clear()
|
||||
}
|
||||
if v.Op == OpStore {
|
||||
if v.Op == OpStore || v.Op == OpZero {
|
||||
if shadowed.contains(v.Args[0].ID) {
|
||||
// Modify store into a copy
|
||||
v.Op = OpCopy
|
||||
if v.Op == OpStore {
|
||||
// store addr value mem
|
||||
v.SetArgs1(v.Args[2])
|
||||
} else {
|
||||
// zero addr mem
|
||||
sz := v.Args[0].Type.Elem().Size()
|
||||
if v.AuxInt != sz {
|
||||
f.Fatalf("mismatched zero/store sizes: %d and %d [%s]",
|
||||
v.AuxInt, sz, v.LongString())
|
||||
}
|
||||
v.SetArgs1(v.Args[1])
|
||||
}
|
||||
v.Aux = nil
|
||||
v.SetArgs1(v.Args[2])
|
||||
v.AuxInt = 0
|
||||
v.Op = OpCopy
|
||||
} else {
|
||||
shadowed.add(v.Args[0].ID)
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
|
||||
package ssa
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func TestDeadStore(t *testing.T) {
|
||||
c := testConfig(t)
|
||||
@ -18,9 +16,12 @@ func TestDeadStore(t *testing.T) {
|
||||
Valu("v", OpConstBool, TypeBool, 0, true),
|
||||
Valu("addr1", OpAddr, ptrType, 0, nil, "sb"),
|
||||
Valu("addr2", OpAddr, ptrType, 0, nil, "sb"),
|
||||
Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "start"),
|
||||
Valu("addr3", OpAddr, ptrType, 0, nil, "sb"),
|
||||
Valu("zero1", OpZero, TypeMem, 8, nil, "addr3", "start"),
|
||||
Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "zero1"),
|
||||
Valu("store2", OpStore, TypeMem, 0, nil, "addr2", "v", "store1"),
|
||||
Valu("store3", OpStore, TypeMem, 0, nil, "addr1", "v", "store2"),
|
||||
Valu("store4", OpStore, TypeMem, 0, nil, "addr3", "v", "store3"),
|
||||
Goto("exit")),
|
||||
Bloc("exit",
|
||||
Exit("store3")))
|
||||
@ -29,10 +30,15 @@ func TestDeadStore(t *testing.T) {
|
||||
dse(fun.f)
|
||||
CheckFunc(fun.f)
|
||||
|
||||
v := fun.values["store1"]
|
||||
if v.Op != OpCopy {
|
||||
v1 := fun.values["store1"]
|
||||
if v1.Op != OpCopy {
|
||||
t.Errorf("dead store not removed")
|
||||
}
|
||||
|
||||
v2 := fun.values["zero1"]
|
||||
if v2.Op != OpCopy {
|
||||
t.Errorf("dead store (zero) not removed")
|
||||
}
|
||||
}
|
||||
func TestDeadStorePhi(t *testing.T) {
|
||||
// make sure we don't get into an infinite loop with phi values.
|
||||
|
Loading…
Reference in New Issue
Block a user