summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/fuse_test.go
diff options
context:
space:
mode:
authorAlexandru Moșoi <mosoi@google.com>2016-02-17 17:21:53 +0100
committerAlexandru Moșoi <alexandru@mosoi.ro>2016-02-19 22:44:29 +0000
commit5949524fc48aa514154cfb939ae28af58aaf6540 (patch)
tree036d445a640ce0d93a03caaff7a3032cd8d4a82f /src/cmd/compile/internal/ssa/fuse_test.go
parente4bee4be9276dc5a7ba5e06aa9d287cbf39d8758 (diff)
downloadgo-git-5949524fc48aa514154cfb939ae28af58aaf6540.tar.gz
[dev.ssa] cmd/compile/internal/ssa: handle phis in fuse.
Change-Id: Idd880cc6c1e5dc34dddbdea0841a7a718d2fa836 Reviewed-on: https://go-review.googlesource.com/19544 Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/fuse_test.go')
-rw-r--r--src/cmd/compile/internal/ssa/fuse_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/fuse_test.go b/src/cmd/compile/internal/ssa/fuse_test.go
index b6f6b82c35..3ce8ea54b3 100644
--- a/src/cmd/compile/internal/ssa/fuse_test.go
+++ b/src/cmd/compile/internal/ssa/fuse_test.go
@@ -65,6 +65,40 @@ func TestFuseEliminatesBothBranches(t *testing.T) {
}
}
+func TestFuseHandlesPhis(t *testing.T) {
+ ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing
+ c := NewConfig("amd64", DummyFrontend{t}, nil, true)
+ fun := Fun(c, "entry",
+ Bloc("entry",
+ Valu("mem", OpInitMem, TypeMem, 0, nil),
+ Valu("sb", OpSB, TypeInvalid, 0, nil),
+ Goto("checkPtr")),
+ Bloc("checkPtr",
+ Valu("ptr1", OpLoad, ptrType, 0, nil, "sb", "mem"),
+ Valu("nilptr", OpConstNil, ptrType, 0, nil, "sb"),
+ Valu("bool1", OpNeqPtr, TypeBool, 0, nil, "ptr1", "nilptr"),
+ If("bool1", "then", "else")),
+ Bloc("then",
+ Goto("exit")),
+ Bloc("else",
+ Goto("exit")),
+ Bloc("exit",
+ Valu("phi", OpPhi, ptrType, 0, nil, "ptr1", "ptr1"),
+ Exit("mem")))
+
+ CheckFunc(fun.f)
+ fuse(fun.f)
+
+ for _, b := range fun.f.Blocks {
+ if b == fun.blocks["then"] && b.Kind != BlockInvalid {
+ 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")
+ }
+ }
+}
+
func TestFuseEliminatesEmptyBlocks(t *testing.T) {
c := NewConfig("amd64", DummyFrontend{t}, nil, true)
fun := Fun(c, "entry",