Skip to content

Commit 3fda376

Browse files
committed
cmd/compile: fix regression in PPC64.rules move zero
When a MOVDstorezero (8 bytes) is used the offset field in the instruction must be a multiple of 4. This situation had been corrected in the rules for other types of stores but not for the zero case. This also removes some of the special MOVDstorezero cases since they can be handled by the general LowerZero case. Updates made to the ssa test for lowering zero moves to include cases where the target is not aligned to at least 4. Fixes #21947 Change-Id: I7cceceb1be4898c77cd3b5e78b58dce0a7e28edd Reviewed-on: https://go-review.googlesource.com/64970 Run-TryBot: Lynn Boger <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Carlos Eduardo Seo <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 8e2d90d commit 3fda376

File tree

4 files changed

+350
-159
lines changed

4 files changed

+350
-159
lines changed

src/cmd/compile/internal/gc/testdata/gen/zeroGen.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
// will be written into the parent directory containing the tests.
2020

2121
var sizes = [...]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 23, 24, 25, 31, 32, 33, 63, 64, 65, 1023, 1024, 1025}
22+
var usizes = [...]int{8, 16, 24, 32, 64, 256}
2223

2324
func main() {
2425
w := new(bytes.Buffer)
@@ -61,12 +62,74 @@ func main() {
6162
fmt.Fprintf(w, "}\n")
6263
}
6364

65+
for _, s := range usizes {
66+
// type for test
67+
fmt.Fprintf(w, "type T%du1 struct {\n", s)
68+
fmt.Fprintf(w, " b bool\n")
69+
fmt.Fprintf(w, " val [%d]byte\n", s)
70+
fmt.Fprintf(w, "}\n")
71+
72+
fmt.Fprintf(w, "type T%du2 struct {\n", s)
73+
fmt.Fprintf(w, " i uint16\n")
74+
fmt.Fprintf(w, " val [%d]byte\n", s)
75+
fmt.Fprintf(w, "}\n")
76+
77+
// function being tested
78+
fmt.Fprintf(w, "//go:noinline\n")
79+
fmt.Fprintf(w, "func zero%du1_ssa(t *T%du1) {\n", s, s)
80+
fmt.Fprintf(w, " t.val = [%d]byte{}\n", s)
81+
fmt.Fprintf(w, "}\n")
82+
83+
// function being tested
84+
fmt.Fprintf(w, "//go:noinline\n")
85+
fmt.Fprintf(w, "func zero%du2_ssa(t *T%du2) {\n", s, s)
86+
fmt.Fprintf(w, " t.val = [%d]byte{}\n", s)
87+
fmt.Fprintf(w, "}\n")
88+
89+
// testing harness
90+
fmt.Fprintf(w, "func testZero%du() {\n", s)
91+
fmt.Fprintf(w, " a := T%du1{false, [%d]byte{", s, s)
92+
for i := 0; i < s; i++ {
93+
fmt.Fprintf(w, "255,")
94+
}
95+
fmt.Fprintf(w, "}}\n")
96+
fmt.Fprintf(w, " zero%du1_ssa(&a)\n", s)
97+
fmt.Fprintf(w, " want := T%du1{false, [%d]byte{", s, s)
98+
for i := 0; i < s; i++ {
99+
fmt.Fprintf(w, "0,")
100+
}
101+
fmt.Fprintf(w, "}}\n")
102+
fmt.Fprintf(w, " if a != want {\n")
103+
fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", a, want)\n", s)
104+
fmt.Fprintf(w, " failed=true\n")
105+
fmt.Fprintf(w, " }\n")
106+
fmt.Fprintf(w, " b := T%du2{15, [%d]byte{", s, s)
107+
for i := 0; i < s; i++ {
108+
fmt.Fprintf(w, "255,")
109+
}
110+
fmt.Fprintf(w, "}}\n")
111+
fmt.Fprintf(w, " zero%du2_ssa(&b)\n", s)
112+
fmt.Fprintf(w, " wantb := T%du2{15, [%d]byte{", s, s)
113+
for i := 0; i < s; i++ {
114+
fmt.Fprintf(w, "0,")
115+
}
116+
fmt.Fprintf(w, "}}\n")
117+
fmt.Fprintf(w, " if b != wantb {\n")
118+
fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", b, wantb)\n", s)
119+
fmt.Fprintf(w, " failed=true\n")
120+
fmt.Fprintf(w, " }\n")
121+
fmt.Fprintf(w, "}\n")
122+
}
123+
64124
// boilerplate at end
65125
fmt.Fprintf(w, "var failed bool\n")
66126
fmt.Fprintf(w, "func main() {\n")
67127
for _, s := range sizes {
68128
fmt.Fprintf(w, " testZero%d()\n", s)
69129
}
130+
for _, s := range usizes {
131+
fmt.Fprintf(w, " testZero%du()\n", s)
132+
}
70133
fmt.Fprintf(w, " if failed {\n")
71134
fmt.Fprintf(w, " panic(\"failed\")\n")
72135
fmt.Fprintf(w, " }\n")

src/cmd/compile/internal/gc/testdata/zero.go

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

src/cmd/compile/internal/ssa/gen/PPC64.rules

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -572,49 +572,29 @@
572572
(MOVBstorezero [6] destptr
573573
(MOVHstorezero [4] destptr
574574
(MOVWstorezero destptr mem)))
575-
(Zero [8] destptr mem) ->
576-
(MOVDstorezero destptr mem)
577575

578-
// Zero small numbers of words directly.
579-
(Zero [12] destptr mem) ->
576+
// MOVD for store with DS must have offsets that are multiple of 4
577+
(Zero [8] {t} destptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
578+
(MOVDstorezero destptr mem)
579+
(Zero [8] destptr mem) ->
580+
(MOVWstorezero [4] destptr
581+
(MOVWstorezero [0] destptr mem))
582+
// Handle these cases only if aligned properly, otherwise use general case below
583+
(Zero [12] {t} destptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
580584
(MOVWstorezero [8] destptr
581585
(MOVDstorezero [0] destptr mem))
582-
(Zero [16] destptr mem) ->
583-
(MOVDstorezero [8] destptr
586+
(Zero [16] {t} destptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
587+
(MOVDstorezero [8] destptr
584588
(MOVDstorezero [0] destptr mem))
585-
(Zero [24] destptr mem) ->
586-
(MOVDstorezero [16] destptr
587-
(MOVDstorezero [8] destptr
588-
(MOVDstorezero [0] destptr mem)))
589-
(Zero [32] destptr mem) ->
590-
(MOVDstorezero [24] destptr
591-
(MOVDstorezero [16] destptr
592-
(MOVDstorezero [8] destptr
593-
(MOVDstorezero [0] destptr mem))))
594-
595-
(Zero [40] destptr mem) ->
596-
(MOVDstorezero [32] destptr
597-
(MOVDstorezero [24] destptr
598-
(MOVDstorezero [16] destptr
599-
(MOVDstorezero [8] destptr
600-
(MOVDstorezero [0] destptr mem)))))
601-
602-
(Zero [48] destptr mem) ->
603-
(MOVDstorezero [40] destptr
604-
(MOVDstorezero [32] destptr
605-
(MOVDstorezero [24] destptr
606-
(MOVDstorezero [16] destptr
607-
(MOVDstorezero [8] destptr
608-
(MOVDstorezero [0] destptr mem))))))
609-
610-
(Zero [56] destptr mem) ->
611-
(MOVDstorezero [48] destptr
612-
(MOVDstorezero [40] destptr
613-
(MOVDstorezero [32] destptr
614-
(MOVDstorezero [24] destptr
615-
(MOVDstorezero [16] destptr
616-
(MOVDstorezero [8] destptr
617-
(MOVDstorezero [0] destptr mem)))))))
589+
(Zero [24] {t} destptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
590+
(MOVDstorezero [16] destptr
591+
(MOVDstorezero [8] destptr
592+
(MOVDstorezero [0] destptr mem)))
593+
(Zero [32] {t} destptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
594+
(MOVDstorezero [24] destptr
595+
(MOVDstorezero [16] destptr
596+
(MOVDstorezero [8] destptr
597+
(MOVDstorezero [0] destptr mem))))
618598

619599
// Handle cases not handled above
620600
(Zero [s] ptr mem) -> (LoweredZero [s] ptr mem)

0 commit comments

Comments
 (0)