github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/test/testdata/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 // Tests phi implementation 6 7 package main 8 9 import "testing" 10 11 func phiOverwrite_ssa() int { 12 var n int 13 for i := 0; i < 10; i++ { 14 if i == 6 { 15 break 16 } 17 n = i 18 } 19 return n 20 } 21 22 func phiOverwrite(t *testing.T) { 23 want := 5 24 got := phiOverwrite_ssa() 25 if got != want { 26 t.Errorf("phiOverwrite_ssa()= %d, got %d", want, got) 27 } 28 } 29 30 func phiOverwriteBig_ssa() int { 31 var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z int 32 a = 1 33 for idx := 0; idx < 26; idx++ { 34 a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z = b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a 35 } 36 return a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i*9 + j*10 + k*11 + l*12 + m*13 + n*14 + o*15 + p*16 + q*17 + r*18 + s*19 + t*20 + u*21 + v*22 + w*23 + x*24 + y*25 + z*26 37 } 38 39 func phiOverwriteBig(t *testing.T) { 40 want := 1 41 got := phiOverwriteBig_ssa() 42 if got != want { 43 t.Errorf("phiOverwriteBig_ssa()= %d, got %d", want, got) 44 } 45 } 46 47 func TestRegalloc(t *testing.T) { 48 phiOverwrite(t) 49 phiOverwriteBig(t) 50 }