1
0
mirror of https://github.com/golang/go synced 2024-11-24 07:40:17 -07:00

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 <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Austin Clements 2022-05-02 14:54:22 -04:00
parent d4bfc87218
commit 3b01a80319

View File

@ -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