]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: declare no output register for loong64 LoweredAtomic{And,Or}32 ops
authorWANG Xuerui <git@xen0n.name>
Thu, 9 Oct 2025 07:52:02 +0000 (15:52 +0800)
committerabner chenc <chenguoqi@loongson.cn>
Fri, 10 Oct 2025 01:07:03 +0000 (18:07 -0700)
The ICE seen on loong64 while compiling the `(*gcWork).tryStealSpan`
function was due to an `LoweredAtomicAnd32` op (inlined from the
`(pMask).clear` implementation) being incorrectly assigned an output
register while it shouldn't have. Because the op is of mem type, it has
needRegister() == false; hence in the shuffle phase of regalloc, its
bogus output register has no associated `orig` value recorded. The bug
was introduced in CL 482756, but only recently exposed by CL 696035.

Since the old-style atomic ops need no return value (and is even
documented so besides the loong64 ssa op definition), just fix the
register info for both.

While at it, add a note in the ssa op definition file about the
architectural necessity of resultNotInArgs for loong64 atomic ops,
because the practice is not seen in several other arches I have
checked.

Updates #75776

Change-Id: I087f51b8a2825d7b00fc3965b0afcc8b02cad277
Reviewed-on: https://go-review.googlesource.com/c/go/+/710475
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go
src/cmd/compile/internal/ssa/opGen.go

index a85a566660eee62fabdffdca698ca69a82161368..7e8b8bf497b8ffa7d9d7ec745d514e843e41fc30 100644 (file)
@@ -143,6 +143,7 @@ func init() {
                gp2load   = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{gp}}
                gpstore   = regInfo{inputs: []regMask{gpspsbg, gpg}}
                gpstore2  = regInfo{inputs: []regMask{gpspsbg, gpg, gpg | rz}}
+               gpoldatom = regInfo{inputs: []regMask{gpspsbg, gpg}}
                gpxchg    = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{gp}}
                gpcas     = regInfo{inputs: []regMask{gpspsbg, gpg, gpg}, outputs: []regMask{gp}}
                preldreg  = regInfo{inputs: []regMask{gpspg}}
@@ -431,6 +432,12 @@ func init() {
                        faultOnNilArg1: true,
                },
 
+               // Atomic operations.
+               //
+               // resultNotInArgs is needed by all ops lowering to LoongArch
+               // atomic memory access instructions, because these instructions
+               // are defined to require rd != rj && rd != rk per the ISA spec.
+
                // atomic loads.
                // load from arg0. arg1=mem.
                // returns <value,memory> so they can be properly ordered with other loads.
@@ -500,8 +507,8 @@ func init() {
 
                // Atomic 32 bit AND/OR.
                // *arg0 &= (|=) arg1. arg2=mem. returns nil.
-               {name: "LoweredAtomicAnd32", argLength: 3, reg: gpxchg, asm: "AMANDDBW", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true},
-               {name: "LoweredAtomicOr32", argLength: 3, reg: gpxchg, asm: "AMORDBW", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true},
+               {name: "LoweredAtomicAnd32", argLength: 3, reg: gpoldatom, asm: "AMANDDBW", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true},
+               {name: "LoweredAtomicOr32", argLength: 3, reg: gpoldatom, asm: "AMORDBW", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true},
 
                // Atomic 32,64 bit AND/OR.
                // *arg0 &= (|=) arg1. arg2=mem. returns <old content of *arg0, memory>. auxint must be zero.
index 32ba3a89856ed411baf07af221e8d6c3fed73e4e..3ed1619e4a6ab921455a03cab2de69d4f25ff09a 100644 (file)
@@ -26392,9 +26392,6 @@ var opcodeTable = [...]opInfo{
                                {1, 1073741816},          // R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 g R23 R24 R25 R26 R27 R28 R29 R31
                                {0, 4611686019501129724}, // SP R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 g R23 R24 R25 R26 R27 R28 R29 R31 SB
                        },
-                       outputs: []outputInfo{
-                               {0, 1071644664}, // R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R23 R24 R25 R26 R27 R28 R29 R31
-                       },
                },
        },
        {
@@ -26409,9 +26406,6 @@ var opcodeTable = [...]opInfo{
                                {1, 1073741816},          // R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 g R23 R24 R25 R26 R27 R28 R29 R31
                                {0, 4611686019501129724}, // SP R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 g R23 R24 R25 R26 R27 R28 R29 R31 SB
                        },
-                       outputs: []outputInfo{
-                               {0, 1071644664}, // R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R23 R24 R25 R26 R27 R28 R29 R31
-                       },
                },
        },
        {