Skip to content

Commit 0ae3b7c

Browse files
committed
cmd/compile: fix rules regression with shifts on PPC64
Some rules for PPC64 were checking for a case where a shift followed by an 'and' of a mask could be lowered, depending on the format of the mask. The function to verify if the mask was valid for this purpose was not checking if the mask was 0 which we don't want to allow. This case can happen if previous optimizations resulted in that mask value. This fixes isPPC64ValidShiftMask to check for a mask of 0 and return false. This also adds a codegen testcase to verify it doesn't try to match the rules in the future. Fixes #42610 Change-Id: I565d94e88495f51321ab365d6388c01e791b4dbb Reviewed-on: https://go-review.googlesource.com/c/go/+/270358 Run-TryBot: Lynn Boger <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Paul Murphy <[email protected]> Reviewed-by: Carlos Eduardo Seo <[email protected]> Trust: Lynn Boger <[email protected]>
1 parent 869e295 commit 0ae3b7c

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,10 +1427,11 @@ func DecodePPC64RotateMask(sauxint int64) (rotate, mb, me int64, mask uint64) {
14271427
return
14281428
}
14291429

1430-
// This verifies that the mask occupies the
1431-
// rightmost bits.
1430+
// This verifies that the mask is a set of
1431+
// consecutive bits including the least
1432+
// significant bit.
14321433
func isPPC64ValidShiftMask(v int64) bool {
1433-
if ((v + 1) & v) == 0 {
1434+
if (v != 0) && ((v+1)&v) == 0 {
14341435
return true
14351436
}
14361437
return false

test/codegen/issue42610.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// asmcheck
2+
3+
// Copyright 2020 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+
// Don't allow 0 masks in shift lowering rules on ppc64x.
8+
// See issue 42610.
9+
10+
package codegen
11+
12+
func f32(a []int32, i uint32) {
13+
g := func(p int32) int32 {
14+
i = uint32(p) * (uint32(p) & (i & 1))
15+
return 1
16+
}
17+
// ppc64le: -"RLWNIM"
18+
// ppc64: -"RLWNIM"
19+
a[0] = g(8) >> 1
20+
}
21+
22+
func f(a []int, i uint) {
23+
g := func(p int) int {
24+
i = uint(p) * (uint(p) & (i & 1))
25+
return 1
26+
}
27+
// ppc64le: -"RLDIC"
28+
// ppc64: -"RLDIC"
29+
a[0] = g(8) >> 1
30+
}

0 commit comments

Comments
 (0)