diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:18:25 +0000 |
commit | 109be507377fe7f6e8819ac94041d3fdcdf6fd2f (patch) | |
tree | 2806a689f8fab4a2ec9fc949830ef270a91d667d /test/opt_branchlikely.go | |
parent | Initial commit. (diff) | |
download | golang-1.19-upstream.tar.xz golang-1.19-upstream.zip |
Adding upstream version 1.19.8.upstream/1.19.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/opt_branchlikely.go')
-rw-r--r-- | test/opt_branchlikely.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/opt_branchlikely.go b/test/opt_branchlikely.go new file mode 100644 index 0000000..884c349 --- /dev/null +++ b/test/opt_branchlikely.go @@ -0,0 +1,86 @@ +// +build amd64 +// errorcheck -0 -d=ssa/likelyadjust/debug=1,ssa/insert_resched_checks/off +// rescheduling check insertion is turned off because the inserted conditional branches perturb the errorcheck + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that branches have some prediction properties. +package foo + +func f(x, y, z int) int { + a := 0 + for i := 0; i < x; i++ { // ERROR "Branch prediction rule stay in loop" + for j := 0; j < y; j++ { // ERROR "Branch prediction rule stay in loop" + a += j + } + for k := 0; k < z; k++ { // ERROR "Branch prediction rule stay in loop" + a -= x + y + z + } + } + return a +} + +func g(x, y, z int) int { + a := 0 + if y == 0 { // ERROR "Branch prediction rule default < call" + y = g(y, z, x) + } else { + y++ + } + if y == x { // ERROR "Branch prediction rule default < call" + y = g(y, z, x) + } else { + } + if y == 2 { // ERROR "Branch prediction rule default < call" + z++ + } else { + y = g(z, x, y) + } + if y+z == 3 { // ERROR "Branch prediction rule call < exit" + println("ha ha") + } else { + panic("help help help") + } + if x != 0 { // ERROR "Branch prediction rule default < ret" + for i := 0; i < x; i++ { // ERROR "Branch prediction rule stay in loop" + if x == 4 { // ERROR "Branch prediction rule stay in loop" + return a + } + for j := 0; j < y; j++ { // ERROR "Branch prediction rule stay in loop" + for k := 0; k < z; k++ { // ERROR "Branch prediction rule stay in loop" + a -= j * i + } + a += j + } + } + } + return a +} + +func h(x, y, z int) int { + a := 0 + for i := 0; i < x; i++ { // ERROR "Branch prediction rule stay in loop" + for j := 0; j < y; j++ { // ERROR "Branch prediction rule stay in loop" + a += j + if i == j { // ERROR "Branch prediction rule stay in loop" + break + } + a *= j + } + for k := 0; k < z; k++ { // ERROR "Branch prediction rule stay in loop" + a -= k + if i == k { + continue + } + a *= k + } + } + if a > 0 { // ERROR "Branch prediction rule default < call" + a = g(x, y, z) + } else { + a = -a + } + return a +} |