Skip to content

Commit fc145ac

Browse files
mdempskybradfitz
authored andcommitted
cmd/compile/internal/ssagen: fix min/max codegen, again
The large-function phi placement algorithm evidently doesn't like the same pseudo-variable being used to represent expressions of varying types. Instead, use the same tactic as used for "valVar" (ssa.go:6585--6587), which is to just generate a fresh marker node each time. Maybe we could just use the OMIN/OMAX nodes themselves as the key (like we do for OANDAND/OOROR), but that just seems needlessly risky for negligible memory savings. Using fresh marker values each time seems obviously safe by comparison. Fixes golang#61041. Change-Id: Ie2600c9c37b599c2e26ae01f5f8a433025d7fd08 Reviewed-on: https://go-review.googlesource.com/c/go/+/506679 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent b3b0c6b commit fc145ac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,6 @@ var (
949949
typVar = ssaMarker("typ")
950950
okVar = ssaMarker("ok")
951951
deferBitsVar = ssaMarker("deferBits")
952-
ternaryVar = ssaMarker("ternary")
953952
)
954953

955954
// startBlock sets the current block we're generating code in to b.
@@ -3621,6 +3620,10 @@ func (s *state) minMax(n *ir.CallExpr) *ssa.Value {
36213620

36223621
// ternary emits code to evaluate cond ? x : y.
36233622
func (s *state) ternary(cond, x, y *ssa.Value) *ssa.Value {
3623+
// Note that we need a new ternaryVar each time (unlike okVar where we can
3624+
// reuse the variable) because it might have a different type every time.
3625+
ternaryVar := ssaMarker("ternary")
3626+
36243627
bThen := s.f.NewBlock(ssa.BlockPlain)
36253628
bElse := s.f.NewBlock(ssa.BlockPlain)
36263629
bEnd := s.f.NewBlock(ssa.BlockPlain)

test/fixedbugs/issue60982.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
package main
88

9-
func f(x int) int {
9+
func f(x int, b bool) int {
1010
if x >= 1000 {
11+
if b { // from #61041
12+
var a struct{ f int64 }
13+
_ = max(0, a.f)
14+
}
15+
1116
return max(x, 2000)
1217
}
1318
// generate 1000 basic blocks to put this function

0 commit comments

Comments
 (0)