]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/loopbce.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / loopbce.go
index 4ae9a6a630b91208057cacb31d0b4f5cfddedd18..04c186be0eb194d52db47beb6955c0b4e7f5003e 100644 (file)
@@ -1,6 +1,7 @@
-// +build amd64
 // errorcheck -0 -d=ssa/prove/debug=1
 
+//go:build amd64
+
 package main
 
 import "math"
@@ -49,7 +50,7 @@ func f2(a []int) int {
 
 func f4(a [10]int) int {
        x := 0
-       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,10\), increment 2$"
+       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
                x += a[i] // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
        }
        return x
@@ -57,8 +58,32 @@ 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,10\), increment 2$"
-               x += a[i]
+       for i := -10; i < len(a); i += 2 { // ERROR "Induction variable: limits \[-10,8\], increment 2$"
+               x += a[i+10]
+       }
+       return x
+}
+
+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+10]
+       }
+       return x
+}
+
+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+10]
+       }
+       return x
+}
+
+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+10]
        }
        return x
 }
@@ -121,7 +146,7 @@ func g0f(a string) int {
 func g1() int {
        a := "evenlength"
        x := 0
-       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,10\), increment 2$"
+       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
                x += int(a[i]) // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
        }
        return x
@@ -130,7 +155,7 @@ func g1() int {
 func g2() int {
        a := "evenlength"
        x := 0
-       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,10\), increment 2$"
+       for i := 0; i < len(a); i += 2 { // ERROR "Induction variable: limits \[0,8\], increment 2$"
                j := i
                if a[i] == 'e' { // ERROR "(\([0-9]+\) )?Proved IsInBounds$"
                        j = j + 1
@@ -142,9 +167,11 @@ func g2() int {
 
 func g3a() {
        a := "this string has length 25"
-       for i := 0; i < len(a); i += 5 { // ERROR "Induction variable: limits \[0,25\), increment 5$"
+       for i := 0; i < len(a); i += 5 { // ERROR "Induction variable: limits \[0,20\], increment 5$"
                useString(a[i:]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
-               useString(a[:i+3])
+               useString(a[:i+3]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
+               useString(a[:i+5]) // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"
+               useString(a[:i+6])
        }
 }
 
@@ -175,6 +202,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$"
@@ -188,6 +219,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$"
@@ -203,6 +238,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$"
@@ -217,6 +256,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
@@ -226,6 +269,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
@@ -235,6 +282,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
@@ -293,22 +344,22 @@ func d3(a [100]int) [100]int {
 }
 
 func d4() {
-       for i := int64(math.MaxInt64 - 9); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775805\), increment 4$"
+       for i := int64(math.MaxInt64 - 9); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775802\], increment 4$"
                useString("foo")
        }
-       for i := int64(math.MaxInt64 - 8); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775805\), increment 4$"
+       for i := int64(math.MaxInt64 - 8); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775803\], increment 4$"
                useString("foo")
        }
        for i := int64(math.MaxInt64 - 7); i < math.MaxInt64-2; i += 4 {
                useString("foo")
        }
-       for i := int64(math.MaxInt64 - 6); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775801,9223372036854775805\), increment 4$"
+       for i := int64(math.MaxInt64 - 6); i < math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775801,9223372036854775801\], increment 4$"
                useString("foo")
        }
-       for i := int64(math.MaxInt64 - 9); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775805\], increment 4$"
+       for i := int64(math.MaxInt64 - 9); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775798,9223372036854775802\], increment 4$"
                useString("foo")
        }
-       for i := int64(math.MaxInt64 - 8); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775805\], increment 4$"
+       for i := int64(math.MaxInt64 - 8); i <= math.MaxInt64-2; i += 4 { // ERROR "Induction variable: limits \[9223372036854775799,9223372036854775803\], increment 4$"
                useString("foo")
        }
        for i := int64(math.MaxInt64 - 7); i <= math.MaxInt64-2; i += 4 {
@@ -320,22 +371,22 @@ func d4() {
 }
 
 func d5() {
-       for i := int64(math.MinInt64 + 9); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \(-9223372036854775806,-9223372036854775799\], increment 4"
+       for i := int64(math.MinInt64 + 9); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775803,-9223372036854775799\], increment 4"
                useString("foo")
        }
-       for i := int64(math.MinInt64 + 8); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \(-9223372036854775806,-9223372036854775800\], increment 4"
+       for i := int64(math.MinInt64 + 8); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775804,-9223372036854775800\], increment 4"
                useString("foo")
        }
        for i := int64(math.MinInt64 + 7); i > math.MinInt64+2; i -= 4 {
                useString("foo")
        }
-       for i := int64(math.MinInt64 + 6); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \(-9223372036854775806,-9223372036854775802\], increment 4"
+       for i := int64(math.MinInt64 + 6); i > math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775802,-9223372036854775802\], increment 4"
                useString("foo")
        }
-       for i := int64(math.MinInt64 + 9); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775806,-9223372036854775799\], increment 4"
+       for i := int64(math.MinInt64 + 9); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775803,-9223372036854775799\], increment 4"
                useString("foo")
        }
-       for i := int64(math.MinInt64 + 8); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775806,-9223372036854775800\], increment 4"
+       for i := int64(math.MinInt64 + 8); i >= math.MinInt64+2; i -= 4 { // ERROR "Induction variable: limits \[-9223372036854775804,-9223372036854775800\], increment 4"
                useString("foo")
        }
        for i := int64(math.MinInt64 + 7); i >= math.MinInt64+2; i -= 4 {
@@ -356,7 +407,7 @@ func bce1() {
                panic("invalid test: modulos should differ")
        }
 
-       for i := b; i < a; i += z { // ERROR "Induction variable: limits \[-1547,9223372036854774057\), increment 1337"
+       for i := b; i < a; i += z { // ERROR "Induction variable: limits \[-1547,9223372036854772720\], increment 1337"
                useString("foobar")
        }
 }
@@ -385,7 +436,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
 }
@@ -400,6 +450,22 @@ func issue26116a(a []int) {
        }
 }
 
+func stride1(x *[7]int) int {
+       s := 0
+       for i := 0; i <= 8; i += 3 { // ERROR "Induction variable: limits \[0,6\], increment 3"
+               s += x[i] // ERROR "Proved IsInBounds"
+       }
+       return s
+}
+
+func stride2(x *[7]int) int {
+       s := 0
+       for i := 0; i < 9; i += 3 { // ERROR "Induction variable: limits \[0,6\], increment 3"
+               s += x[i] // ERROR "Proved IsInBounds"
+       }
+       return s
+}
+
 //go:noinline
 func useString(a string) {
 }