]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix for zerorange on plan9-amd64
authorThan McIntosh <thanm@google.com>
Mon, 5 Apr 2021 20:50:38 +0000 (16:50 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 5 Apr 2021 23:21:16 +0000 (23:21 +0000)
In CL 305829 a problematic change was made to the compiler's
amd64-specific "zerorange" function. In zerorange the compiler uses
different sets of strategies depending on the size of the stack frame
it needs to zero; turns out that only on plan9-amd64 was it hitting
the final fallback strategy, which is a REPSTOSQ instruction. REPSTOSQ
takes RAX as an input, hence the changes made in CL 305829 (switching
to R13) were incorrect.

This patch restores the zerorange REPSTOSQ sequence (back to use RAX).
This is going to be an interim solution, since long term we need to
avoid touching RAX in the function prolog (since if the new register
ABI is in effect, it will hold a live value).

Fixes #45372.

Change-Id: Ic89a6a2a76d6e03b9fbda99275101e96b70fdf5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/307469
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/amd64/ggen.go

index e56ec90dc87370c66930fe0b9f756a8c66331638..f065bb4dd447f8d18c07016d484938a4179d6966 100644 (file)
@@ -58,6 +58,7 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
        const (
                r13 = 1 << iota // if R13 is already zeroed.
                x15             // if X15 is already zeroed. Note: in new ABI, X15 is always zero.
+               rax             // if RAX is already zeroed.
        )
 
        if cnt == 0 {
@@ -116,9 +117,12 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.
                p = pp.Append(p, x86.AMOVQ, obj.TYPE_REG, x86.REG_R12, 0, obj.TYPE_REG, x86.REG_DI, 0)
 
        } else {
-               if *state&r13 == 0 {
-                       p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_R13, 0)
-                       *state |= r13
+               // Note: here we have to use RAX since it is an implicit input
+               // for the REPSTOSQ below. This is going to be problematic when
+               // regabi is in effect; this will be fixed in a forthcoming CL.
+               if *state&rax == 0 {
+                       p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, x86.REG_AX, 0)
+                       *state |= rax
                }
 
                p = pp.Append(p, x86.AMOVQ, obj.TYPE_CONST, 0, cnt/int64(types.RegSize), obj.TYPE_REG, x86.REG_CX, 0)