1
2
3
4
5 package ssa
6
7 import (
8 "testing"
9
10 "cmd/compile/internal/abt"
11 "cmd/compile/internal/ssa/ssaop"
12 )
13
14
15
16 func TestVarLocHighRegister(t *testing.T) {
17 const lo, hi = 3, 70
18
19 loc := VarLoc{Registers: RegisterSet{}.AddReg(hi)}
20 if loc.absent() {
21 t.Fatalf("location in register %d is absent", hi)
22 }
23 if got := firstReg(loc.Registers); got != hi {
24 t.Errorf("firstReg = %d, want %d", got, hi)
25 }
26
27 both := VarLoc{Registers: loc.Registers.AddReg(lo)}
28 if got := both.intersect(loc); got.Registers != loc.Registers {
29 t.Errorf("intersect = %v, want %v", got.Registers, loc.Registers)
30 }
31 if !canMerge(loc, both) {
32 t.Errorf("canMerge(%v, %v) = false, want true", loc.Registers, both.Registers)
33 }
34 if canMerge(both, loc) {
35 t.Errorf("canMerge(%v, %v) = true, want false", both.Registers, loc.Registers)
36 }
37 if got := both.Registers.RemoveReg(ssaop.Register(hi)); got.HasReg(hi) || !got.HasReg(lo) {
38 t.Errorf("RemoveReg(%d) = %v", hi, got)
39 }
40
41 var live abt.T
42 live.Insert(0, &liveSlot{both})
43 state := StateAtPC{slots: make([]VarLoc, 1), registers: make([][]SlotID, hi+1)}
44 state.reset(live)
45 for _, r := range []int{lo, hi} {
46 if len(state.registers[r]) != 1 || state.registers[r][0] != 0 {
47 t.Errorf("registers[%d] = %v, want [0]", r, state.registers[r])
48 }
49 }
50 }
51
View as plain text