mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: don't fuse branches with side effects
Count Values with side effects but no use as live, and don't fuse branches that contain such Values. (This can happen e.g. when it is followed by an infinite loop.) Otherwise this may lead to miscompilation (side effect fired at wrong condition) or ICE (two stores live simultaneously). Fixes #36005. Change-Id: If202eae4b37cb7f0311d6ca120ffa46609925157 Reviewed-on: https://go-review.googlesource.com/c/go/+/210179 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
eeb319a5a5
commit
7673884a7f
4 changed files with 39 additions and 3 deletions
|
|
@ -63,7 +63,7 @@ func TestFuseEliminatesBothBranches(t *testing.T) {
|
|||
t.Errorf("then was not eliminated, but should have")
|
||||
}
|
||||
if b == fun.blocks["else"] && b.Kind != BlockInvalid {
|
||||
t.Errorf("then was not eliminated, but should have")
|
||||
t.Errorf("else was not eliminated, but should have")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ func TestFuseHandlesPhis(t *testing.T) {
|
|||
t.Errorf("then was not eliminated, but should have")
|
||||
}
|
||||
if b == fun.blocks["else"] && b.Kind != BlockInvalid {
|
||||
t.Errorf("then was not eliminated, but should have")
|
||||
t.Errorf("else was not eliminated, but should have")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -131,6 +131,40 @@ func TestFuseEliminatesEmptyBlocks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFuseSideEffects(t *testing.T) {
|
||||
// Test that we don't fuse branches that have side effects but
|
||||
// have no use (e.g. followed by infinite loop).
|
||||
// See issue #36005.
|
||||
c := testConfig(t)
|
||||
fun := c.Fun("entry",
|
||||
Bloc("entry",
|
||||
Valu("mem", OpInitMem, types.TypeMem, 0, nil),
|
||||
Valu("b", OpArg, c.config.Types.Bool, 0, nil),
|
||||
If("b", "then", "else")),
|
||||
Bloc("then",
|
||||
Valu("call1", OpStaticCall, types.TypeMem, 0, nil, "mem"),
|
||||
Goto("empty")),
|
||||
Bloc("else",
|
||||
Valu("call2", OpStaticCall, types.TypeMem, 0, nil, "mem"),
|
||||
Goto("empty")),
|
||||
Bloc("empty",
|
||||
Goto("loop")),
|
||||
Bloc("loop",
|
||||
Goto("loop")))
|
||||
|
||||
CheckFunc(fun.f)
|
||||
fuseAll(fun.f)
|
||||
|
||||
for _, b := range fun.f.Blocks {
|
||||
if b == fun.blocks["then"] && b.Kind == BlockInvalid {
|
||||
t.Errorf("then is eliminated, but should not")
|
||||
}
|
||||
if b == fun.blocks["else"] && b.Kind == BlockInvalid {
|
||||
t.Errorf("else is eliminated, but should not")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFuse(b *testing.B) {
|
||||
for _, n := range [...]int{1, 10, 100, 1000, 10000} {
|
||||
b.Run(strconv.Itoa(n), func(b *testing.B) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue