aboutsummaryrefslogtreecommitdiff
path: root/test/prove.go
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2024-01-10 07:31:57 +0100
committerGopher Robot <gobot@golang.org>2024-01-23 00:02:36 +0000
commitbbd0bc22ea4bc447a4d009db7d5137688820896d (patch)
tree2bc5744f46afe2f2d8e4da9be085d5144a6a0eb1 /test/prove.go
parent370f1a88edfec10c071fbf700328048a83bee9fc (diff)
downloadgo-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/prove.go')
-rw-r--r--test/prove.go21
1 files changed, 15 insertions, 6 deletions
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]
}