Skip to content

Commit 8a44c8e

Browse files
committed
cmd/compile: don't spill rematerializeable value when resolving merge edges
Fixes #19515. Change-Id: I4bcce152cef52d00fbb5ab4daf72a6e742bae27c Reviewed-on: https://go-review.googlesource.com/38158 Reviewed-by: Keith Randall <[email protected]>
1 parent 2d78538 commit 8a44c8e

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

src/cmd/compile/internal/ssa/regalloc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,7 @@ func (e *edgeState) findRegFor(typ Type) Location {
22272227
// 1) an unused register
22282228
// 2) a non-unique register not holding a final value
22292229
// 3) a non-unique register
2230+
// 4) TODO: a register holding a rematerializeable value
22302231
x := m &^ e.usedRegs
22312232
if x != 0 {
22322233
return &e.s.registers[pickReg(x)]
@@ -2252,10 +2253,12 @@ func (e *edgeState) findRegFor(typ Type) Location {
22522253
a := e.cache[vid]
22532254
for _, c := range a {
22542255
if r, ok := e.s.f.getHome(c.ID).(*Register); ok && m>>uint(r.num)&1 != 0 {
2255-
x := e.p.NewValue1(c.Pos, OpStoreReg, c.Type, c)
2256-
e.set(t, vid, x, false, c.Pos)
2257-
if e.s.f.pass.debug > regDebug {
2258-
fmt.Printf(" SPILL %s->%s %s\n", r.Name(), t.Name(), x.LongString())
2256+
if !c.rematerializeable() {
2257+
x := e.p.NewValue1(c.Pos, OpStoreReg, c.Type, c)
2258+
e.set(t, vid, x, false, c.Pos)
2259+
if e.s.f.pass.debug > regDebug {
2260+
fmt.Printf(" SPILL %s->%s %s\n", r.Name(), t.Name(), x.LongString())
2261+
}
22592262
}
22602263
// r will now be overwritten by the caller. At some point
22612264
// later, the newly saved value will be moved back to its

test/fixedbugs/issue19515.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// compile
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 19515: compiler panics on spilling int128 constant.
8+
9+
package x
10+
11+
type VScrollPanel struct {
12+
x, y int
13+
}
14+
15+
type Color struct {
16+
R, G, B, A float32
17+
}
18+
19+
func maxF(a, b float32) float32 {
20+
if a > b {
21+
return 0
22+
}
23+
return 1
24+
}
25+
26+
type TransformMatrix [6]float32
27+
28+
type Paint struct {
29+
xform TransformMatrix
30+
feather float32
31+
innerColor Color
32+
outerColor Color
33+
}
34+
35+
func BoxGradient(x, y, w, h, f float32, iColor, oColor Color) Paint {
36+
return Paint{
37+
xform: TransformMatrix{9, 0, 0, 0, x, y},
38+
feather: maxF(1.0, f),
39+
innerColor: iColor,
40+
outerColor: oColor,
41+
}
42+
}
43+
44+
func (v *VScrollPanel) Draw() {
45+
x := float32(v.x)
46+
y := float32(v.y)
47+
48+
BoxGradient(x+x-2, y-1, 0, 0, 0, Color{}, Color{})
49+
BoxGradient(x+y-2, y-1, 0, 0, 0, Color{}, Color{})
50+
}
51+

0 commit comments

Comments
 (0)