aboutsummaryrefslogtreecommitdiff
path: root/test/loopbce.go
diff options
context:
space:
mode:
authorYi Yang <qingfeng.yy@alibaba-inc.com>2023-08-31 02:48:34 +0000
committerKeith Randall <khr@golang.org>2023-09-12 21:01:50 +0000
commit4ee1d542eda8d8aab7ca2024a4a0a9068d3cad70 (patch)
tree4c8d6efa3ca9b5d88d7d8c0f1f7f7c3f49fdd6a9 /test/loopbce.go
parenta843991fdd079c931d4e98c0a17c9ac6dc254fe8 (diff)
downloadgo-4ee1d542eda8d8aab7ca2024a4a0a9068d3cad70.tar.gz
go-4ee1d542eda8d8aab7ca2024a4a0a9068d3cad70.zip
cmd/compile: sparse conditional constant propagation
sparse conditional constant propagation can discover optimization opportunities that cannot be found by just combining constant folding and constant propagation and dead code elimination separately. This is a re-submit of PR#59575, which fix a broken dominance relationship caught by ssacheck Updates https://github.com/golang/go/issues/59399 Change-Id: I57482dee38f8e80a610aed4f64295e60c38b7a47 GitHub-Last-Rev: 830016f24e3a5320c6c127a48ab7c84e2fc672eb GitHub-Pull-Request: golang/go#60469 Reviewed-on: https://go-review.googlesource.com/c/go/+/498795 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/loopbce.go')
-rw-r--r--test/loopbce.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/test/loopbce.go b/test/loopbce.go
index fcf0d8d90d..1119aaa65a 100644
--- a/test/loopbce.go
+++ b/test/loopbce.go
@@ -58,7 +58,7 @@ func f4(a [10]int) int {
func f5(a [10]int) int {
x := 0
for i := -10; i < len(a); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
- x += a[i]
+ x += a[i+10]
}
return x
}
@@ -66,7 +66,7 @@ func f5(a [10]int) int {
func f5_int32(a [10]int) int {
x := 0
for i := int32(-10); i < int32(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
- x += a[i]
+ x += a[i+10]
}
return x
}
@@ -74,7 +74,7 @@ func f5_int32(a [10]int) int {
func f5_int16(a [10]int) int {
x := 0
for i := int16(-10); i < int16(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
- x += a[i]
+ x += a[i+10]
}
return x
}
@@ -82,7 +82,7 @@ func f5_int16(a [10]int) int {
func f5_int8(a [10]int) int {
x := 0
for i := int8(-10); i < int8(len(a)); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
- x += a[i]
+ x += a[i+10]
}
return x
}
@@ -201,6 +201,10 @@ func h2(a []byte) {
func k0(a [100]int) [100]int {
for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
a[i-11] = i
a[i-10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
a[i-5] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
@@ -214,6 +218,10 @@ func k0(a [100]int) [100]int {
func k1(a [100]int) [100]int {
for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
useSlice(a[:i-11])
useSlice(a[:i-10]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
useSlice(a[:i-5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
@@ -229,6 +237,10 @@ func k1(a [100]int) [100]int {
func k2(a [100]int) [100]int {
for i := 10; i < 90; i++ { // ERROR "Induction variable: limits \[10,90\), increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
useSlice(a[i-11:])
useSlice(a[i-10:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
useSlice(a[i-5:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
@@ -243,6 +255,10 @@ func k2(a [100]int) [100]int {
func k3(a [100]int) [100]int {
for i := -10; i < 90; i++ { // ERROR "Induction variable: limits \[-10,90\), increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
a[i+9] = i
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
a[i+11] = i
@@ -252,6 +268,10 @@ func k3(a [100]int) [100]int {
func k3neg(a [100]int) [100]int {
for i := 89; i > -11; i-- { // ERROR "Induction variable: limits \(-11,89\], increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
a[i+9] = i
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
a[i+11] = i
@@ -261,6 +281,10 @@ func k3neg(a [100]int) [100]int {
func k3neg2(a [100]int) [100]int {
for i := 89; i >= -10; i-- { // ERROR "Induction variable: limits \[-10,89\], increment 1$"
+ if a[0] == 0xdeadbeef {
+ // This is a trick to prohibit sccp to optimize out the following out of bound check
+ continue
+ }
a[i+9] = i
a[i+10] = i // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
a[i+11] = i
@@ -411,7 +435,6 @@ func nobce3(a [100]int64) [100]int64 {
min := int64((-1) << 63)
max := int64((1 << 63) - 1)
for i := min; i < max; i++ { // ERROR "Induction variable: limits \[-9223372036854775808,9223372036854775807\), increment 1$"
- a[i] = i
}
return a
}