diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2025-11-18 01:42:37 +0100 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-11-21 12:37:30 -0800 |
| commit | ec92bc6d63efdbd1e04b7590b8ec3ea5236503e0 (patch) | |
| tree | df6444de3fa55fd85dab213762f592e81a2998d0 /test | |
| parent | 3820f94c1d081921494ada1da64b4fab21ae1a48 (diff) | |
| download | go-ec92bc6d63efdbd1e04b7590b8ec3ea5236503e0.tar.xz | |
cmd/compile: rewrite Rsh to RshU if arguments are proved positive
Fixes #76332
Change-Id: I9044025d5dc599531c7f88ed2870bcf3d8b0acbd
Reviewed-on: https://go-review.googlesource.com/c/go/+/721206
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/prove.go | 6 | ||||
| -rw-r--r-- | test/prove_constant_folding.go | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/test/prove.go b/test/prove.go index 38181b5fa5..e440634813 100644 --- a/test/prove.go +++ b/test/prove.go @@ -253,7 +253,7 @@ func f9(a, b bool) int { func f10(a string) int { n := len(a) - b := a[:n>>1] // ERROR "Proved IsSliceInBounds$" + b := a[:n>>1] // ERROR "(Proved IsSliceInBounds|Proved Rsh64x64 is unsigned)$" // We optimize comparisons with small constant strings (see cmd/compile/internal/gc/walk.go), // so this string literal must be long. if b == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" { @@ -1086,7 +1086,7 @@ func issue57077(s []int) (left, right []int) { } func issue76332(s []int) (left, right []int) { - middle := len(s) >> 1 + middle := len(s) >> 1 // ERROR "Proved Rsh64x64 is unsigned$" left = s[:middle] // ERROR "Proved IsSliceInBounds$" right = s[middle:] // ERROR "Proved IsSliceInBounds$" return @@ -2564,7 +2564,7 @@ func rightshift(v *[256]int) int { } } for i := range 1024 { // ERROR "Induction" - if v[i>>2] == 0 { // ERROR "Proved IsInBounds" + if v[i>>2] == 0 { // ERROR "(Proved IsInBounds|Proved Rsh64x64 is unsigned)" return i } } diff --git a/test/prove_constant_folding.go b/test/prove_constant_folding.go index 46764f9b9d..831a7e6403 100644 --- a/test/prove_constant_folding.go +++ b/test/prove_constant_folding.go @@ -30,10 +30,10 @@ func f0u(x uint) int { } if x < 1000 { - return int(x)>>31 // ERROR "Proved.+is constant 0$" + return int(x) >> 31 // ERROR "(Proved.+is constant 0|Proved Rsh[0-9]+x[0-9]+ is unsigned)$" } if x := int32(x); x < -1000 { - return int(x>>31) // ERROR "Proved.+is constant -1$" + return int(x >> 31) // ERROR "Proved.+is constant -1$" } return int(x) + 1 @@ -45,35 +45,35 @@ func sh64(n int64) int64 { if n < 0 { return n } - return n >> 63 // ERROR "Proved .+ is constant 0$" + return n >> 63 // ERROR "(Proved .+ is constant 0|Proved Rsh[0-9]+x[0-9]+ is unsigned)$" } func sh32(n int32) int32 { if n < 0 { return n } - return n >> 31 // ERROR "Proved .+ is constant 0$" + return n >> 31 // ERROR "(Proved .+ is constant 0|Proved Rsh[0-9]+x[0-9]+ is unsigned)$" } func sh32x64(n int32) int32 { if n < 0 { return n } - return n >> uint64(31) // ERROR "Proved .+ is constant 0$" + return n >> uint64(31) // ERROR "(Proved .+ is constant 0|Proved Rsh[0-9]+x[0-9]+ is unsigned)$" } func sh32x64n(n int32) int32 { if n >= 0 { return 0 } - return n >> 31// ERROR "Proved .+ is constant -1$" + return n >> 31 // ERROR "Proved .+ is constant -1$" } func sh16(n int16) int16 { if n < 0 { return n } - return n >> 15 // ERROR "Proved .+ is constant 0$" + return n >> 15 // ERROR "(Proved .+ is constant 0|Proved Rsh[0-9]+x[0-9]+ is unsigned)$" } func sh64noopt(n int64) int64 { |
