mirror of
https://github.com/golang/go
synced 2024-11-26 00:17:58 -07:00
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 #61041. Change-Id: Ie2600c9c37b599c2e26ae01f5f8a433025d7fd08 Reviewed-on: https://go-review.googlesource.com/c/go/+/506679 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
a3093eca64
commit
79d4defa75
@ -949,7 +949,6 @@ var (
|
|||||||
typVar = ssaMarker("typ")
|
typVar = ssaMarker("typ")
|
||||||
okVar = ssaMarker("ok")
|
okVar = ssaMarker("ok")
|
||||||
deferBitsVar = ssaMarker("deferBits")
|
deferBitsVar = ssaMarker("deferBits")
|
||||||
ternaryVar = ssaMarker("ternary")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// startBlock sets the current block we're generating code in to b.
|
// 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 {
|
|||||||
|
|
||||||
// ternary emits code to evaluate cond ? x : y.
|
// ternary emits code to evaluate cond ? x : y.
|
||||||
func (s *state) ternary(cond, x, y *ssa.Value) *ssa.Value {
|
func (s *state) ternary(cond, x, y *ssa.Value) *ssa.Value {
|
||||||
|
// Note that we need a new ternaryVar each time (unlike okVar where we can
|
||||||
|
// reuse the variable) because it might have a different type every time.
|
||||||
|
ternaryVar := ssaMarker("ternary")
|
||||||
|
|
||||||
bThen := s.f.NewBlock(ssa.BlockPlain)
|
bThen := s.f.NewBlock(ssa.BlockPlain)
|
||||||
bElse := s.f.NewBlock(ssa.BlockPlain)
|
bElse := s.f.NewBlock(ssa.BlockPlain)
|
||||||
bEnd := s.f.NewBlock(ssa.BlockPlain)
|
bEnd := s.f.NewBlock(ssa.BlockPlain)
|
||||||
|
@ -6,8 +6,13 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func f(x int) int {
|
func f(x int, b bool) int {
|
||||||
if x >= 1000 {
|
if x >= 1000 {
|
||||||
|
if b { // from #61041
|
||||||
|
var a struct{ f int64 }
|
||||||
|
_ = max(0, a.f)
|
||||||
|
}
|
||||||
|
|
||||||
return max(x, 2000)
|
return max(x, 2000)
|
||||||
}
|
}
|
||||||
// generate 1000 basic blocks to put this function
|
// generate 1000 basic blocks to put this function
|
||||||
|
Loading…
Reference in New Issue
Block a user