github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/compile/internal/ssa/shortcircuit_test.go (about)

     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 "testing"
     8  
     9  func TestShortCircuit(t *testing.T) {
    10  	c := testConfig(t)
    11  
    12  	fun := Fun(c, "entry",
    13  		Bloc("entry",
    14  			Valu("mem", OpInitMem, TypeMem, 0, nil),
    15  			Valu("arg1", OpArg, TypeInt64, 0, nil),
    16  			Valu("arg2", OpArg, TypeInt64, 0, nil),
    17  			Valu("arg3", OpArg, TypeInt64, 0, nil),
    18  			Goto("b1")),
    19  		Bloc("b1",
    20  			Valu("cmp1", OpLess64, TypeBool, 0, nil, "arg1", "arg2"),
    21  			If("cmp1", "b2", "b3")),
    22  		Bloc("b2",
    23  			Valu("cmp2", OpLess64, TypeBool, 0, nil, "arg2", "arg3"),
    24  			Goto("b3")),
    25  		Bloc("b3",
    26  			Valu("phi2", OpPhi, TypeBool, 0, nil, "cmp1", "cmp2"),
    27  			If("phi2", "b4", "b5")),
    28  		Bloc("b4",
    29  			Valu("cmp3", OpLess64, TypeBool, 0, nil, "arg3", "arg1"),
    30  			Goto("b5")),
    31  		Bloc("b5",
    32  			Valu("phi3", OpPhi, TypeBool, 0, nil, "phi2", "cmp3"),
    33  			If("phi3", "b6", "b7")),
    34  		Bloc("b6",
    35  			Exit("mem")),
    36  		Bloc("b7",
    37  			Exit("mem")))
    38  
    39  	CheckFunc(fun.f)
    40  	shortcircuit(fun.f)
    41  	CheckFunc(fun.f)
    42  
    43  	for _, b := range fun.f.Blocks {
    44  		for _, v := range b.Values {
    45  			if v.Op == OpPhi {
    46  				t.Errorf("phi %s remains", v)
    47  			}
    48  		}
    49  	}
    50  }