aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2023-07-25 16:19:10 +0200
committerGopher Robot <gobot@golang.org>2023-07-31 18:33:29 +0000
commitbac4e2f241ca8df3d5be6ddf83214b9a681f4086 (patch)
tree6fcd6b62c19354d7e6ba9496a764976982db0c16 /test/codegen
parent8613ef81e676bda77f6413a587e68c3dcc5b03ae (diff)
downloadgo-bac4e2f241ca8df3d5be6ddf83214b9a681f4086.tar.xz
cmd/compile: try to rewrite loops to count down
Fixes #61629 This reduce the pressure on regalloc because then the loop only keep alive one value (the iterator) instead of the iterator and the upper bound since the comparison now acts against an immediate, often zero which can be skipped. This optimize things like: for i := 0; i < n; i++ { Or a range over a slice where the index is not used: for _, v := range someSlice { Or the new range over int from #61405: for range n { It is hit in 975 unique places while doing ./make.bash. Change-Id: I5facff8b267a0b60ea3c1b9a58c4d74cdb38f03f Reviewed-on: https://go-review.googlesource.com/c/go/+/512935 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/compare_and_branch.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/test/codegen/compare_and_branch.go b/test/codegen/compare_and_branch.go
index b3feef0eb7..3502a03022 100644
--- a/test/codegen/compare_and_branch.go
+++ b/test/codegen/compare_and_branch.go
@@ -23,24 +23,25 @@ func si64(x, y chan int64) {
}
// Signed 64-bit compare-and-branch with 8-bit immediate.
-func si64x8() {
+func si64x8(doNotOptimize int64) {
+ // take in doNotOptimize as an argument to avoid the loops being rewritten to count down
// s390x:"CGIJ\t[$]12, R[0-9]+, [$]127, "
- for i := int64(0); i < 128; i++ {
+ for i := doNotOptimize; i < 128; i++ {
dummy()
}
// s390x:"CGIJ\t[$]10, R[0-9]+, [$]-128, "
- for i := int64(0); i > -129; i-- {
+ for i := doNotOptimize; i > -129; i-- {
dummy()
}
// s390x:"CGIJ\t[$]2, R[0-9]+, [$]127, "
- for i := int64(0); i >= 128; i++ {
+ for i := doNotOptimize; i >= 128; i++ {
dummy()
}
// s390x:"CGIJ\t[$]4, R[0-9]+, [$]-128, "
- for i := int64(0); i <= -129; i-- {
+ for i := doNotOptimize; i <= -129; i-- {
dummy()
}
}
@@ -95,24 +96,25 @@ func si32(x, y chan int32) {
}
// Signed 32-bit compare-and-branch with 8-bit immediate.
-func si32x8() {
+func si32x8(doNotOptimize int32) {
+ // take in doNotOptimize as an argument to avoid the loops being rewritten to count down
// s390x:"CIJ\t[$]12, R[0-9]+, [$]127, "
- for i := int32(0); i < 128; i++ {
+ for i := doNotOptimize; i < 128; i++ {
dummy()
}
// s390x:"CIJ\t[$]10, R[0-9]+, [$]-128, "
- for i := int32(0); i > -129; i-- {
+ for i := doNotOptimize; i > -129; i-- {
dummy()
}
// s390x:"CIJ\t[$]2, R[0-9]+, [$]127, "
- for i := int32(0); i >= 128; i++ {
+ for i := doNotOptimize; i >= 128; i++ {
dummy()
}
// s390x:"CIJ\t[$]4, R[0-9]+, [$]-128, "
- for i := int32(0); i <= -129; i-- {
+ for i := doNotOptimize; i <= -129; i-- {
dummy()
}
}