1
2
3
4
5 package ssacompile
6
7 import (
8 "testing"
9
10 "cmd/compile/internal/ssa/ssaop"
11 "cmd/compile/internal/types"
12 )
13
14 func TestShortCircuit(t *testing.T) {
15 c := testConfig(t)
16
17 fun := c.Fun("entry",
18 Bloc("entry",
19 Valu("mem", ssaop.OpInitMem, types.TypeMem, 0, nil),
20 Valu("arg1", ssaop.OpArg, c.config.Types.Int64, 0, nil),
21 Valu("arg2", ssaop.OpArg, c.config.Types.Int64, 0, nil),
22 Valu("arg3", ssaop.OpArg, c.config.Types.Int64, 0, nil),
23 Goto("b1")),
24 Bloc("b1",
25 Valu("cmp1", ssaop.OpLess64, c.config.Types.Bool, 0, nil, "arg1", "arg2"),
26 If("cmp1", "b2", "b3")),
27 Bloc("b2",
28 Valu("cmp2", ssaop.OpLess64, c.config.Types.Bool, 0, nil, "arg2", "arg3"),
29 Goto("b3")),
30 Bloc("b3",
31 Valu("phi2", ssaop.OpPhi, c.config.Types.Bool, 0, nil, "cmp1", "cmp2"),
32 If("phi2", "b4", "b5")),
33 Bloc("b4",
34 Valu("cmp3", ssaop.OpLess64, c.config.Types.Bool, 0, nil, "arg3", "arg1"),
35 Goto("b5")),
36 Bloc("b5",
37 Valu("phi3", ssaop.OpPhi, c.config.Types.Bool, 0, nil, "phi2", "cmp3"),
38 If("phi3", "b6", "b7")),
39 Bloc("b6",
40 Exit("mem")),
41 Bloc("b7",
42 Exit("mem")))
43
44 CheckFunc(fun.f)
45 shortcircuit(fun.f)
46 CheckFunc(fun.f)
47
48 for _, b := range fun.f.Blocks {
49 for _, v := range b.Values {
50 if v.Op == ssaop.OpPhi {
51 t.Errorf("phi %s remains", v)
52 }
53 }
54 }
55 }
56
View as plain text