From fa50248ce6dfbe8afb18a67aa4d0d0cd3800a329 Mon Sep 17 00:00:00 2001 From: Yi Yang Date: Thu, 18 May 2023 11:17:11 +0000 Subject: 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. Updates #59399 Change-Id: Ia954e906480654a6f0cc065d75b5912f96f36b2e GitHub-Last-Rev: 90fc02db99f817b7f0ce5c584642ab1b166e62d7 GitHub-Pull-Request: golang/go#59575 Reviewed-on: https://go-review.googlesource.com/c/go/+/483875 Reviewed-by: Keith Randall Reviewed-by: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt Run-TryBot: Keith Randall --- test/loopbce.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'test/loopbce.go') 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 } -- cgit v1.3