Skip to content

Commit c8fb0ec

Browse files
pmurceseo
authored andcommitted
cmd/compile: fix ANDI/SRWI merge on ppc64
The shift amount should be masked to avoid rotation values beyond the numer of bits. In this case, if the shift amount is 0, it should rotate 0, not 32. Fixes #45589 Change-Id: I1e764497a39d0ec128e29af42352b70c70b2ecc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/310569 Run-TryBot: Paul Murphy <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Lynn Boger <[email protected]> Reviewed-by: Carlos Eduardo Seo <[email protected]> Trust: Carlos Eduardo Seo <[email protected]>
1 parent 699a7c0 commit c8fb0ec

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ func mergePPC64AndSrwi(m, s int64) int64 {
14921492
if !isPPC64WordRotateMask(mask) {
14931493
return 0
14941494
}
1495-
return encodePPC64RotateMask(32-s, mask, 32)
1495+
return encodePPC64RotateMask((32-s)&31, mask, 32)
14961496
}
14971497

14981498
// Test if a shift right feeding into a CLRLSLDI can be merged into RLWINM.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func TestMergePPC64AndSrwi(t *testing.T) {
205205
{0x00000000, 4, false, 0, 0},
206206
{0xF0000000, 4, false, 0, 0},
207207
{0xF0000000, 32, false, 0, 0},
208+
{0xFFFFFFFF, 0, true, 0, 0xFFFFFFFF},
208209
}
209210
for i, v := range tests {
210211
result := mergePPC64AndSrwi(v.and, v.srw)

0 commit comments

Comments
 (0)