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