Skip to content

Commit ae10914

Browse files
committed
cmd/compile: mark LAA and LAAG as clobbering flags on s390x
The atomic add instructions modify the condition code and so need to be marked as clobbering flags. Fixes #24449. Change-Id: Ic69c8d775fbdbfb2a56c5e0cfca7a49c0d7f6897 Reviewed-on: https://go-review.googlesource.com/101455 Run-TryBot: Michael Munday <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 9c31224 commit ae10914

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

src/cmd/compile/internal/ssa/gen/S390XOps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ func init() {
491491
// Atomic adds.
492492
// *(arg0+auxint+aux) += arg1. arg2=mem.
493493
// Returns a tuple of <old contents of *(arg0+auxint+aux), memory>.
494-
{name: "LAA", argLength: 3, reg: gpstorelaa, asm: "LAA", typ: "(UInt32,Mem)", aux: "SymOff", faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"},
495-
{name: "LAAG", argLength: 3, reg: gpstorelaa, asm: "LAAG", typ: "(UInt64,Mem)", aux: "SymOff", faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"},
494+
{name: "LAA", argLength: 3, reg: gpstorelaa, asm: "LAA", typ: "(UInt32,Mem)", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"},
495+
{name: "LAAG", argLength: 3, reg: gpstorelaa, asm: "LAAG", typ: "(UInt64,Mem)", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"},
496496
{name: "AddTupleFirst32", argLength: 2}, // arg1=tuple <x,y>. Returns <x+arg0,y>.
497497
{name: "AddTupleFirst64", argLength: 2}, // arg1=tuple <x,y>. Returns <x+arg0,y>.
498498

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue24449.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// run
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import (
10+
"sync/atomic"
11+
)
12+
13+
var cnt32 int32
14+
15+
//go:noinline
16+
func test32(a, b []int) bool {
17+
// Try to generate flag value, issue atomic
18+
// adds and then re-use the flag value to see if
19+
// the atomic add has clobbered them.
20+
atomic.AddInt32(&cnt32, 1)
21+
if len(a) == len(b) {
22+
atomic.AddInt32(&cnt32, 2)
23+
}
24+
atomic.AddInt32(&cnt32, 4)
25+
if len(a) >= len(b) {
26+
atomic.AddInt32(&cnt32, 8)
27+
}
28+
if len(a) <= len(b) {
29+
atomic.AddInt32(&cnt32, 16)
30+
}
31+
return atomic.LoadInt32(&cnt32) == 31
32+
}
33+
34+
var cnt64 int64
35+
36+
//go:noinline
37+
func test64(a, b []int) bool {
38+
// Try to generate flag value, issue atomic
39+
// adds and then re-use the flag value to see if
40+
// the atomic add has clobbered them.
41+
atomic.AddInt64(&cnt64, 1)
42+
if len(a) == len(b) {
43+
atomic.AddInt64(&cnt64, 2)
44+
}
45+
atomic.AddInt64(&cnt64, 4)
46+
if len(a) >= len(b) {
47+
atomic.AddInt64(&cnt64, 8)
48+
}
49+
if len(a) <= len(b) {
50+
atomic.AddInt64(&cnt64, 16)
51+
}
52+
return atomic.LoadInt64(&cnt64) == 31
53+
}
54+
55+
func main() {
56+
if !test32([]int{}, []int{}) {
57+
panic("test32")
58+
}
59+
if !test64([]int{}, []int{}) {
60+
panic("test64")
61+
}
62+
}

0 commit comments

Comments
 (0)