From 3aad2d0765b9f652e1964a8261d6ef0035d9535f Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Mon, 22 Apr 2024 16:16:30 -0500 Subject: [PATCH] cmd/internal/obj/ppc64: fix incorrect int to int64 conversion when checking MOVD opcodes A type conversion from int to int64 was done in the wrong place causing some MOVD $const, Rx operations to be incorrectly transformed on 32 bit hosts cross-compiling for ppc64x. Fixes #66955 Change-Id: I023ba267a8dac6d6bd22f8146c0d9d2d473bc5c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/580796 Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Joedian Reid Reviewed-by: Lynn Boger Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/cmd/asm/internal/asm/testdata/ppc64.s | 4 ++++ src/cmd/internal/obj/ppc64/obj9.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/ppc64.s b/src/cmd/asm/internal/asm/testdata/ppc64.s index fc56a9530a..8627408f06 100644 --- a/src/cmd/asm/internal/asm/testdata/ppc64.s +++ b/src/cmd/asm/internal/asm/testdata/ppc64.s @@ -52,6 +52,9 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0 // Hex constant 0xFFFFFFFE00000001 MOVD $-8589934591, R5 // 38a0ffff or 0602000038a00001 + // For #66955. Verify this opcode turns into a load and assembles. + MOVD $-6795364578871345152, R5 // 3ca00000e8a50000 or 04100000e4a00000 + MOVD 8(R3), R4 // e8830008 MOVD (R3)(R4), R5 // 7ca4182a MOVD (R3)(R0), R5 // 7ca0182a @@ -90,6 +93,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0 MOVHBR (R3)(R4), R5 // 7ca41e2c MOVHBR (R3)(R0), R5 // 7ca01e2c MOVHBR (R3), R5 // 7ca01e2c + OR $0, R0, R0 MOVD $foo+4009806848(FP), R5 // 3ca1ef0138a5cc40 or 0600ef0038a1cc40 MOVD $foo(SB), R5 // 3ca0000038a50000 or 0610000038a00000 diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go index a55c402c44..23196875a5 100644 --- a/src/cmd/internal/obj/ppc64/obj9.go +++ b/src/cmd/internal/obj/ppc64/obj9.go @@ -200,8 +200,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { // Is this a shifted 16b constant? If so, rewrite it to avoid a creating and loading a constant. val := p.From.Offset shift := bits.TrailingZeros64(uint64(val)) - mask := 0xFFFF << shift - if val&int64(mask) == val || (val>>(shift+16) == -1 && (val>>shift)<>(shift+16) == -1 && (val>>shift)<>shift, Rto; SLD $shift, Rto q := obj.Appendp(p, c.newprog) q.As = ASLD