]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Revert "cmd/compile: use shorter ANDL/TESTL if upper 32 bits are known to be zero"
authorKeith Randall <khr@golang.org>
Tue, 29 Aug 2023 22:43:02 +0000 (22:43 +0000)
committerKeith Randall <khr@golang.org>
Wed, 30 Aug 2023 15:15:28 +0000 (15:15 +0000)
This reverts commit c1dfbf72e1298df8495171810a553836e5027f98.

Reason for revert: TESTL rule is wrong when the result is used for an ordered comparison.

Fixes #62360

Change-Id: I4d5b6aca24389b0a2bf767bfbc0a9d085359eb38
Reviewed-on: https://go-review.googlesource.com/c/go/+/524255
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/compile/internal/ssa/_gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go
test/fixedbugs/issue62360.go [new file with mode: 0644]

index 090ad90c64e68a82e22b9089e04655af15e0d28d..7840600ef6f44208a1bb68d9217cd4f4f177668a 100644 (file)
 (TESTW (MOVLconst [c]) x) => (TESTWconst [int16(c)] x)
 (TESTB (MOVLconst [c]) x) => (TESTBconst [int8(c)] x)
 
-// shorten bitwise AND/TESTQ if upper 32 bits are known to be zero.
-(ANDQ x y) && (zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3)) => (ANDL x y)
-(TESTQ x y) && (zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3)) => (TESTL x y)
-
 // TEST %reg,%reg is shorter than CMP
 (CMPQconst x [0]) => (TESTQ x x)
 (CMPLconst x [0]) => (TESTL x x)
index 0c87a4b1b519329640354e32f0f46663987d7ac6..5cf5425fdcf14603f6de5a091ea7c8783e59b881 100644 (file)
@@ -3094,22 +3094,6 @@ func rewriteValueAMD64_OpAMD64ANDQ(v *Value) bool {
                v.copyOf(x)
                return true
        }
-       // match: (ANDQ x y)
-       // cond: (zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3))
-       // result: (ANDL x y)
-       for {
-               for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
-                       x := v_0
-                       y := v_1
-                       if !(zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3)) {
-                               continue
-                       }
-                       v.reset(OpAMD64ANDL)
-                       v.AddArg2(x, y)
-                       return true
-               }
-               break
-       }
        // match: (ANDQ x l:(MOVQload [off] {sym} ptr mem))
        // cond: canMergeLoadClobber(v, l, x) && clobber(l)
        // result: (ANDQload x [off] {sym} ptr mem)
@@ -22718,22 +22702,6 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value) bool {
                }
                break
        }
-       // match: (TESTQ x y)
-       // cond: (zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3))
-       // result: (TESTL x y)
-       for {
-               for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
-                       x := v_0
-                       y := v_1
-                       if !(zeroUpper32Bits(x, 3) || zeroUpper32Bits(y, 3)) {
-                               continue
-                       }
-                       v.reset(OpAMD64TESTL)
-                       v.AddArg2(x, y)
-                       return true
-               }
-               break
-       }
        // match: (TESTQ l:(MOVQload {sym} [off] ptr mem) l2)
        // cond: l == l2 && l.Uses == 2 && clobber(l)
        // result: @l.Block (CMPQconstload {sym} [makeValAndOff(0, off)] ptr mem)
diff --git a/test/fixedbugs/issue62360.go b/test/fixedbugs/issue62360.go
new file mode 100644 (file)
index 0000000..e81c60f
--- /dev/null
@@ -0,0 +1,24 @@
+// run
+
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "fmt"
+       "math/big"
+)
+
+//go:noinline
+func f(x uint32) *big.Int {
+       return big.NewInt(int64(x))
+}
+func main() {
+       b := f(0xffffffff)
+       c := big.NewInt(0xffffffff)
+       if b.Cmp(c) != 0 {
+               panic(fmt.Sprintf("b:%x c:%x", b, c))
+       }
+}