diff options
| author | Yi Yang <qingfeng.yy@alibaba-inc.com> | 2023-05-18 11:17:11 +0000 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2023-05-24 02:54:03 +0000 |
| commit | fa50248ce6dfbe8afb18a67aa4d0d0cd3800a329 (patch) | |
| tree | 6b9a4c15d7a8c3902be14927ff7375775d4ba1a8 /test | |
| parent | e7a9ca0a53db4b4f357b5d3caaef65e44ce08a90 (diff) | |
| download | go-fa50248ce6dfbe8afb18a67aa4d0d0cd3800a329.tar.xz | |
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 <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/checkbce.go | 4 | ||||
| -rw-r--r-- | test/codegen/compare_and_branch.go | 12 | ||||
| -rw-r--r-- | test/loopbce.go | 33 |
3 files changed, 38 insertions, 11 deletions
diff --git a/test/checkbce.go b/test/checkbce.go index 6a126099bc..ab31d95283 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -137,6 +137,10 @@ func g4(a [100]int) { useInt(a[i+50]) // The following are out of bounds. + if a[0] == 0xdeadbeef { + // This is a trick to prohibit sccp to optimize out the following out of bound check + continue + } useInt(a[i-11]) // ERROR "Found IsInBounds$" useInt(a[i+51]) // ERROR "Found IsInBounds$" } diff --git a/test/codegen/compare_and_branch.go b/test/codegen/compare_and_branch.go index b3feef0eb7..479bd318be 100644 --- a/test/codegen/compare_and_branch.go +++ b/test/codegen/compare_and_branch.go @@ -35,12 +35,12 @@ func si64x8() { } // s390x:"CGIJ\t[$]2, R[0-9]+, [$]127, " - for i := int64(0); i >= 128; i++ { + for i := int64(129); i >= 128; i-- { dummy() } // s390x:"CGIJ\t[$]4, R[0-9]+, [$]-128, " - for i := int64(0); i <= -129; i-- { + for i := int64(-130); i <= -129; i++ { dummy() } } @@ -71,7 +71,7 @@ func ui64x8() { } // s390x:"CLGIJ\t[$]2, R[0-9]+, [$]255, " - for i := uint64(0); i >= 256; i-- { + for i := uint64(257); i >= 256; i-- { dummy() } @@ -107,12 +107,12 @@ func si32x8() { } // s390x:"CIJ\t[$]2, R[0-9]+, [$]127, " - for i := int32(0); i >= 128; i++ { + for i := int32(129); i >= 128; i-- { dummy() } // s390x:"CIJ\t[$]4, R[0-9]+, [$]-128, " - for i := int32(0); i <= -129; i-- { + for i := int32(-130); i <= -129; i++ { dummy() } } @@ -143,7 +143,7 @@ func ui32x8() { } // s390x:"CLIJ\t[$]2, R[0-9]+, [$]255, " - for i := uint32(0); i >= 256; i-- { + for i := uint32(257); i >= 256; i-- { dummy() } 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 } |
