From 3b01a80319860c3d24a07859e4e9b1173800b786 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 2 May 2022 14:54:22 -0400 Subject: [PATCH] cmd/compile: fix loopreschedchecks for regabi The loopreschedchecks pass (GOEXPERIMENT=preemptibleloops) had bit-rotted in two ways because of the regabi experiment: 1. The call to goschedguarded was generating a pre-regabi StaticCall. This CL updates it to construct a new-style StaticCall. 2. The mem finder did not account for tuples or results containing a mem. This caused it to construct phis that were supposed to thread the mem into the added blocks, but they could instead thread a tuple or results containing a mem, causing things to go wrong later. This CL updates the mem finder to add an op to select out the mem if it finds the last live mem in a block is a tuple or results. This isn't ideal since we'll deadcode out most of these, but it's the easiest thing to do and this is just an experiment. Tested by running the runtime tests. Ideally we'd have a real test for this, but I don't think it's worth the effort for code that clearly hasn't been enabled by anyone for at least a year. Change-Id: I8ed01207637c454b68a551d38986c947e17d520b Reviewed-on: https://go-review.googlesource.com/c/go/+/403475 Run-TryBot: Austin Clements TryBot-Result: Gopher Robot Reviewed-by: David Chase --- src/cmd/compile/internal/ssa/loopreschedchecks.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/loopreschedchecks.go b/src/cmd/compile/internal/ssa/loopreschedchecks.go index 738c62607ad..1326fa5ee8e 100644 --- a/src/cmd/compile/internal/ssa/loopreschedchecks.go +++ b/src/cmd/compile/internal/ssa/loopreschedchecks.go @@ -246,8 +246,8 @@ func insertLoopReschedChecks(f *Func) { // mem1 := call resched (mem0) // goto header resched := f.fe.Syslook("goschedguarded") - // TODO(register args) -- will need more details - mem1 := sched.NewValue1A(bb.Pos, OpStaticCall, types.TypeMem, StaticAuxCall(resched, nil), mem0) + call := sched.NewValue1A(bb.Pos, OpStaticCall, types.TypeResultMem, StaticAuxCall(resched, bb.Func.ABIDefault.ABIAnalyzeTypes(nil, nil, nil)), mem0) + mem1 := sched.NewValue1I(bb.Pos, OpSelectN, types.TypeMem, 0, call) sched.AddEdgeTo(h) headerMemPhi.AddArg(mem1) @@ -448,6 +448,16 @@ func findLastMems(f *Func) []*Value { if last == nil { b.Fatalf("no last store found - cycle?") } + + // If this is a tuple containing a mem, select just + // the mem. This will generate ops we don't need, but + // it's the easiest thing to do. + if last.Type.IsTuple() { + last = b.NewValue1(last.Pos, OpSelect1, types.TypeMem, last) + } else if last.Type.IsResults() { + last = b.NewValue1I(last.Pos, OpSelectN, types.TypeMem, int64(last.Type.NumFields()-1), last) + } + lastMems[b.ID] = last } return lastMems