diff options
author | Jorropo <jorropo.pgm@gmail.com> | 2024-01-10 07:31:57 +0100 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-01-23 00:02:36 +0000 |
commit | bbd0bc22ea4bc447a4d009db7d5137688820896d (patch) | |
tree | 2bc5744f46afe2f2d8e4da9be085d5144a6a0eb1 /test | |
parent | 370f1a88edfec10c071fbf700328048a83bee9fc (diff) | |
download | go-bbd0bc22ea4bc447a4d009db7d5137688820896d.tar.gz go-bbd0bc22ea4bc447a4d009db7d5137688820896d.zip |
cmd/compile: improve integer comparisons with numeric bounds
This do:
- Fold always false or always true comparisons for ints and uint.
- Reduce < and <= where the true set is only one value to == with such value.
Change-Id: Ie9e3f70efd1845bef62db56543f051a50ad2532e
Reviewed-on: https://go-review.googlesource.com/c/go/+/555135
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/fuse.go | 10 | ||||
-rw-r--r-- | test/prove.go | 21 |
2 files changed, 20 insertions, 11 deletions
diff --git a/test/fuse.go b/test/fuse.go index f64a087965..e9205dcc23 100644 --- a/test/fuse.go +++ b/test/fuse.go @@ -33,7 +33,7 @@ func fEqLessU(a uint, f float64) bool { } func fEqLeqU(a uint64, f float64) bool { - return a == 0 && f > Cf2 || a <= 0 && f < -Cf2 // ERROR "Redirect Leq64U based on Eq64$" + return a == 0 && f > Cf2 || a <= 0 && f < -Cf2 // ERROR "Redirect Eq64 based on Eq64$" } func fNeqEq(a int, f float64) bool { @@ -58,7 +58,7 @@ func fNeqLessU(a uint, f float64) bool { } func fNeqLeqU(a uint32, f float64) bool { - return a != 0 && f > Cf2 || a <= 0 && f < -Cf2 // ERROR "Redirect Leq32U based on Neq32$" + return a != 2 && f > Cf2 || a <= 2 && f < -Cf2 // ERROR "Redirect Leq32U based on Neq32$" } func fLessEq(a int, f float64) bool { @@ -110,11 +110,11 @@ func fLessULeqU(a uint64, f float64) bool { } func fLeqUEq(a uint8, f float64) bool { - return a <= 0 && f > Cf2 || a == 0 && f < -Cf2 // ERROR "Redirect Eq8 based on Leq8U$" + return a <= 2 && f > Cf2 || a == 2 && f < -Cf2 // ERROR "Redirect Eq8 based on Leq8U$" } func fLeqUNeq(a uint16, f float64) bool { - return a <= 0 && f > Cf2 || a != 0 && f < -Cf2 // ERROR "Redirect Neq16 based on Leq16U$" + return a <= 2 && f > Cf2 || a != 2 && f < -Cf2 // ERROR "Redirect Neq16 based on Leq16U$" } func fLeqLessU(a uint32, f float64) bool { @@ -122,7 +122,7 @@ func fLeqLessU(a uint32, f float64) bool { } func fLeqLeqU(a uint64, f float64) bool { - return a <= 0 && f > Cf2 || a <= 0 && f < -Cf2 // ERROR "Redirect Leq64U based on Leq64U$" + return a <= 2 && f > Cf2 || a <= 2 && f < -Cf2 // ERROR "Redirect Leq64U based on Leq64U$" } // Arg tests are disabled because the op name is different on amd64 and arm64. diff --git a/test/prove.go b/test/prove.go index 1aea282291..0d93db905a 100644 --- a/test/prove.go +++ b/test/prove.go @@ -396,8 +396,11 @@ func f13e(a int) int { return 0 } -func f13f(a int64) int64 { - if a > math.MaxInt64 { +func f13f(a, b int64) int64 { + if b != math.MaxInt64 { + return 42 + } + if a > b { if a == 0 { // ERROR "Disproved Eq64$" return 1 } @@ -869,9 +872,12 @@ func unrollInclStepTooLarge(a []int) int { } // Not an induction variable (min too small, iterating down) -func unrollDecMin(a []int) int { +func unrollDecMin(a []int, b int) int { + if b != math.MinInt64 { + return 42 + } var i, x int - for i = len(a); i >= math.MinInt64; i -= 2 { + for i = len(a); i >= b; i -= 2 { x += a[i-1] x += a[i-2] } @@ -882,9 +888,12 @@ func unrollDecMin(a []int) int { } // Not an induction variable (min too small, iterating up -- perhaps could allow, but why bother?) -func unrollIncMin(a []int) int { +func unrollIncMin(a []int, b int) int { + if b != math.MinInt64 { + return 42 + } var i, x int - for i = len(a); i >= math.MinInt64; i += 2 { + for i = len(a); i >= b; i += 2 { x += a[i-1] x += a[i-2] } |