]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: fix SCCP propagation into jump tables
authorKeith Randall <khr@golang.org>
Thu, 7 Dec 2023 19:09:29 +0000 (11:09 -0800)
committerKeith Randall <khr@golang.org>
Fri, 8 Dec 2023 00:29:01 +0000 (00:29 +0000)
commit788a22775931ed6ca26426c5bf78ce3716b304ba
treefe4706408f6e238e293544bc209461209783b330
parentdca2ef236151e5606a5863d82f1a10289ce77105
cmd/compile: fix SCCP propagation into jump tables

We can't delete all the outgoing edges and then add one back in, because
then we've lost the argument of any phi at the target. Instead, move
the important target to the front of the list and delete the rest.

This normally isn't a problem, because there is never normally a phi
at the target of a jump table. But this isn't quite true when in race
build mode, because there is a phi of the result of a bunch of raceread
calls.

The reason this happens is that each case is written like this (where e
is the runtime.eface we're switching on):

if e.type == $type.int32 {
   m = raceread(e.data, m1)
}
m2 = phi(m1, m)
if e.type == $type.int32 {
   .. do case ..
   goto blah
}

so that if e.type is not $type.int32, it falls through to the default
case. This default case will have a memory phi for all the (jumped around
and not actually called) raceread calls.

If we instead did it like

if e.type == $type.int32 {
  raceread(e.data)
  .. do case ..
  goto blah
}

That would paper over this bug, as it is the only way to construct
a jump table whose target is a block with a phi in it. (Yet.)

But we'll fix the underlying bug in this CL. Maybe we can do the
rewrite mentioned above later.  (It is an optimization for -race mode,
which isn't particularly important.)

Fixes #64606

Change-Id: I6f6e3c90eb1e2638112920ee2e5b6581cef04ea4
Reviewed-on: https://go-review.googlesource.com/c/go/+/548356
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/ssa/block.go
src/cmd/compile/internal/ssa/deadcode.go
src/cmd/compile/internal/ssa/sccp.go
test/fixedbugs/issue64606.go [new file with mode: 0644]