aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/bits.go
diff options
context:
space:
mode:
authorPaul E. Murphy <murp@ibm.com>2023-07-11 09:07:43 -0500
committerPaul Murphy <murp@ibm.com>2023-07-12 16:34:02 +0000
commit5e4000ad7ff153d90e77c97d7f29d3a2fa6c7de0 (patch)
tree878d8a3ba1b023d500fa8042ae877e70026d277a /test/codegen/bits.go
parentaf8f94e3c5885647d6f85d2d5227b5fc6b637c52 (diff)
downloadgo-5e4000ad7ff153d90e77c97d7f29d3a2fa6c7de0.tar.xz
cmd/compile: on PPC64, fix sign/zero extension when masking
(ANDCCconst [y] (MOV.*reg x)) should only be merged when zero extending. Otherwise, sign bits are lost on negative values. (ANDCCconst [0xFF] (MOVBreg x)) should be simplified to a zero extension of x. Likewise for the MOVHreg variant. Fixes #61297 Change-Id: I04e4fd7dc6a826e870681f37506620d48393698b Reviewed-on: https://go-review.googlesource.com/c/go/+/508775 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'test/codegen/bits.go')
-rw-r--r--test/codegen/bits.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/codegen/bits.go b/test/codegen/bits.go
index 4f70627c25..018f5b909e 100644
--- a/test/codegen/bits.go
+++ b/test/codegen/bits.go
@@ -374,3 +374,23 @@ func foldConstOutOfRange(a uint64) uint64 {
// arm64: "MOVD\t[$]19088744",-"ADD\t[$]19088744"
return a + 0x1234568
}
+
+// Verify sign-extended values are not zero-extended under a bit mask (#61297)
+func signextendAndMask8to64(a int8) (s, z uint64) {
+ // ppc64x: "MOVB", "ANDCC\t[$]1015,"
+ s = uint64(a) & 0x3F7
+ // ppc64x: -"MOVB", "ANDCC\t[$]247,"
+ z = uint64(uint8(a)) & 0x3F7
+ return
+
+}
+
+// Verify zero-extended values are not sign-extended under a bit mask (#61297)
+func zeroextendAndMask8to64(a int8, b int16) (x, y uint64) {
+ // ppc64x: -"MOVB\t", -"ANDCC", "MOVBZ"
+ x = uint64(a) & 0xFF
+ // ppc64x: -"MOVH\t", -"ANDCC", "MOVHZ"
+ y = uint64(b) & 0xFFFF
+ return
+
+}