]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: fix ANDI/SRWI merge on ppc64
authorPaul E. Murphy <murp@ibm.com>
Thu, 15 Apr 2021 18:41:01 +0000 (13:41 -0500)
committerCarlos Eduardo Seo <carlos.seo@linaro.org>
Thu, 15 Apr 2021 21:57:02 +0000 (21:57 +0000)
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 <murp@ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
Trust: Carlos Eduardo Seo <carlos.seo@linaro.org>

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

index b8a9062d8308ecbf3d4d5ff033eaca810e3cdb57..bdc4f799aa242b9922fed2eaa2b4a60c6921f320 100644 (file)
@@ -1492,7 +1492,7 @@ func mergePPC64AndSrwi(m, s int64) int64 {
        if !isPPC64WordRotateMask(mask) {
                return 0
        }
-       return encodePPC64RotateMask(32-s, mask, 32)
+       return encodePPC64RotateMask((32-s)&31, mask, 32)
 }
 
 // Test if a shift right feeding into a CLRLSLDI can be merged into RLWINM.
index 272b080d8810648dbda170206019e562e27b9aeb..357fe1183fad56da349da9af4de47cdff074c59b 100644 (file)
@@ -205,6 +205,7 @@ func TestMergePPC64AndSrwi(t *testing.T) {
                {0x00000000, 4, false, 0, 0},
                {0xF0000000, 4, false, 0, 0},
                {0xF0000000, 32, false, 0, 0},
+               {0xFFFFFFFF, 0, true, 0, 0xFFFFFFFF},
        }
        for i, v := range tests {
                result := mergePPC64AndSrwi(v.and, v.srw)