]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix loopreschedchecks for regabi
authorAustin Clements <austin@google.com>
Mon, 2 May 2022 18:54:22 +0000 (14:54 -0400)
committerAustin Clements <austin@google.com>
Mon, 2 May 2022 19:53:56 +0000 (19:53 +0000)
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>
src/cmd/compile/internal/ssa/loopreschedchecks.go

index 738c62607adb497383bca5e32489277503fe4362..1326fa5ee8e25b333d9d90a5c277190eaebfd9ff 100644 (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