github.com/slayercat/go@v0.0.0-20170428012452-c51559813f61/src/cmd/compile/internal/ssa/regalloc_test.go (about) 1 // Copyright 2015 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/internal/src" 9 "testing" 10 ) 11 12 func TestLiveControlOps(t *testing.T) { 13 c := testConfig(t) 14 f := c.Fun("entry", 15 Bloc("entry", 16 Valu("mem", OpInitMem, TypeMem, 0, nil), 17 Valu("x", OpAMD64MOVLconst, TypeInt8, 1, nil), 18 Valu("y", OpAMD64MOVLconst, TypeInt8, 2, nil), 19 Valu("a", OpAMD64TESTB, TypeFlags, 0, nil, "x", "y"), 20 Valu("b", OpAMD64TESTB, TypeFlags, 0, nil, "y", "x"), 21 Eq("a", "if", "exit"), 22 ), 23 Bloc("if", 24 Eq("b", "plain", "exit"), 25 ), 26 Bloc("plain", 27 Goto("exit"), 28 ), 29 Bloc("exit", 30 Exit("mem"), 31 ), 32 ) 33 flagalloc(f.f) 34 regalloc(f.f) 35 checkFunc(f.f) 36 } 37 38 // Test to make sure we don't push spills into loops. 39 // See issue #19595. 40 func TestSpillWithLoop(t *testing.T) { 41 c := testConfig(t) 42 f := c.Fun("entry", 43 Bloc("entry", 44 Valu("mem", OpInitMem, TypeMem, 0, nil), 45 Valu("ptr", OpArg, TypeInt64Ptr, 0, c.Frontend().Auto(src.NoXPos, TypeInt64)), 46 Valu("cond", OpArg, TypeBool, 0, c.Frontend().Auto(src.NoXPos, TypeBool)), 47 Valu("ld", OpAMD64MOVQload, TypeInt64, 0, nil, "ptr", "mem"), // this value needs a spill 48 Goto("loop"), 49 ), 50 Bloc("loop", 51 Valu("memphi", OpPhi, TypeMem, 0, nil, "mem", "call"), 52 Valu("call", OpAMD64CALLstatic, TypeMem, 0, nil, "memphi"), 53 Valu("test", OpAMD64CMPBconst, TypeFlags, 0, nil, "cond"), 54 Eq("test", "next", "exit"), 55 ), 56 Bloc("next", 57 Goto("loop"), 58 ), 59 Bloc("exit", 60 Valu("store", OpAMD64MOVQstore, TypeMem, 0, nil, "ptr", "ld", "call"), 61 Exit("store"), 62 ), 63 ) 64 regalloc(f.f) 65 checkFunc(f.f) 66 for _, v := range f.blocks["loop"].Values { 67 if v.Op == OpStoreReg { 68 t.Errorf("spill inside loop %s", v.LongString()) 69 } 70 } 71 }