| 1 |
// Copyright 2016 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package ssa |
| 6 |
|
| 7 |
import ( |
| 8 |
"cmd/compile/internal/types" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func TestShortCircuit(t *testing.T) { |
| 13 |
c := testConfig(t) |
| 14 |
|
| 15 |
fun := c.Fun("entry", |
| 16 |
Bloc("entry", |
| 17 |
Valu("mem", OpInitMem, types.TypeMem, 0, nil), |
| 18 |
Valu("arg1", OpArg, c.config.Types.Int64, 0, nil), |
| 19 |
Valu("arg2", OpArg, c.config.Types.Int64, 0, nil), |
| 20 |
Valu("arg3", OpArg, c.config.Types.Int64, 0, nil), |
| 21 |
Goto("b1")), |
| 22 |
Bloc("b1", |
| 23 |
Valu("cmp1", OpLess64, c.config.Types.Bool, 0, nil, "arg1", "arg2"), |
| 24 |
If("cmp1", "b2", "b3")), |
| 25 |
Bloc("b2", |
| 26 |
Valu("cmp2", OpLess64, c.config.Types.Bool, 0, nil, "arg2", "arg3"), |
| 27 |
Goto("b3")), |
| 28 |
Bloc("b3", |
| 29 |
Valu("phi2", OpPhi, c.config.Types.Bool, 0, nil, "cmp1", "cmp2"), |
| 30 |
If("phi2", "b4", "b5")), |
| 31 |
Bloc("b4", |
| 32 |
Valu("cmp3", OpLess64, c.config.Types.Bool, 0, nil, "arg3", "arg1"), |
| 33 |
Goto("b5")), |
| 34 |
Bloc("b5", |
| 35 |
Valu("phi3", OpPhi, c.config.Types.Bool, 0, nil, "phi2", "cmp3"), |
| 36 |
If("phi3", "b6", "b7")), |
| 37 |
Bloc("b6", |
| 38 |
Exit("mem")), |
| 39 |
Bloc("b7", |
| 40 |
Exit("mem"))) |
| 41 |
|
| 42 |
CheckFunc(fun.f) |
| 43 |
shortcircuit(fun.f) |
| 44 |
CheckFunc(fun.f) |
| 45 |
|
| 46 |
for _, b := range fun.f.Blocks { |
| 47 |
for _, v := range b.Values { |
| 48 |
if v.Op == OpPhi { |
| 49 |
t.Errorf("phi %s remains", v) |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |