aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorJunchen Li <junchen.li@arm.com>2020-07-10 11:39:23 +0800
committerKeith Randall <khr@golang.org>2020-08-17 20:06:35 +0000
commite30fbe3757d09a22988835835c41233df7c6cd00 (patch)
treee53cc3bf90165f2b72d849ba58045f7472d1d80a /test/codegen
parent1a3558341860357c2400e37773e5076bb3a51628 (diff)
downloadgo-e30fbe3757d09a22988835835c41233df7c6cd00.tar.gz
go-e30fbe3757d09a22988835835c41233df7c6cd00.zip
cmd/compile: optimize unsigned comparisons to 0
There are some architecture-independent rules in #21439, since an unsigned integer >= 0 is always true and < 0 is always false. This CL adds these optimizations to generic rules. Updates #21439 Change-Id: Iec7e3040b761ecb1e60908f764815fdd9bc62495 Reviewed-on: https://go-review.googlesource.com/c/go/+/246617 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/comparisons.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go
index 90808573c2..f3c15538a8 100644
--- a/test/codegen/comparisons.go
+++ b/test/codegen/comparisons.go
@@ -407,3 +407,20 @@ func CmpToZero_ex5(e, f int32, u uint32) int {
}
return 0
}
+func UintLtZero(a uint8, b uint16, c uint32, d uint64) int {
+ // amd64: -`(TESTB|TESTW|TESTL|TESTQ|JCC|JCS)`
+ // arm64: -`(CMPW|CMP|BHS|BLO)`
+ if a < 0 || b < 0 || c < 0 || d < 0 {
+ return 1
+ }
+ return 0
+}
+
+func UintGeqZero(a uint8, b uint16, c uint32, d uint64) int {
+ // amd64: -`(TESTB|TESTW|TESTL|TESTQ|JCS|JCC)`
+ // arm64: -`(CMPW|CMP|BLO|BHS)`
+ if a >= 0 || b >= 0 || c >= 0 || d >= 0 {
+ return 1
+ }
+ return 0
+}