cmd/compile: register allocation of rematerializable ops ignores the op output register constraints. #70451
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Note: as far as I know, this issue is not reachable with any Go source today, but it may be roadblock as we do more with SIMD.
When preforming register allocation, rematerializable values are not issued immediately.
Instead, when the value is used as an input to a later op,
allocValToReg
will copy the value and then assign it to a register based on theallocValToReg
mask
argument.This
mask
argument is the constraint on the input argument at the point of use. But the rematerializable value also has output register constraints, which are completely ignored. Thus register allocation may assign an invalid register.As far as I know this isn't reachable due to the limited number of rematerializable ops and a limited set of conflicting ops that may take them as an input. The obvious case here is a rematerializable op with a GPR output and users with FP input.
https://go.dev/cl/629815 demonstrates this issue by manually using POR with a int constant. You can build it with
GOARCH=amd64 GOAMD64=v2 go build runtime
, which fails with:Looking at the SSA of
runtime.sweepLocked.countAlloc
, we seeThe problem here is that
MOVQconst
is assigned register X1, even though it has an output constraint for gp registers only.It is unclear to me what we want to happen here. Probably one of:
MOVQconst
toMOVSDconst
.(2) alludes to why I don't think this can be triggered in Go code today: the main incompatibility is between gp and fp registers, but fp registers today are used almost exclusively for float operations, so the inputs are already floats. But if we start doing more SIMD, this will be less true, as many operations treat the fp registers as vectors of non-float types.
cc @golang/compiler @randall77
The text was updated successfully, but these errors were encountered: