summaryrefslogtreecommitdiffstats
path: root/test/phiopt.go
blob: 98a7b75d10911c1fd811e0919af5d70d75d85837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// +build amd64 s390x
// errorcheck -0 -d=ssa/phiopt/debug=3

// 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.

package main

//go:noinline
func f0(a bool) bool {
	x := false
	if a {
		x = true
	} else {
		x = false
	}
	return x // ERROR "converted OpPhi to Copy$"
}

//go:noinline
func f1(a bool) bool {
	x := false
	if a {
		x = false
	} else {
		x = true
	}
	return x // ERROR "converted OpPhi to Not$"
}

//go:noinline
func f2(a, b int) bool {
	x := true
	if a == b {
		x = false
	}
	return x // ERROR "converted OpPhi to Not$"
}

//go:noinline
func f3(a, b int) bool {
	x := false
	if a == b {
		x = true
	}
	return x // ERROR "converted OpPhi to Copy$"
}

//go:noinline
func f4(a, b bool) bool {
	return a || b // ERROR "converted OpPhi to OrB$"
}

//go:noinline
func f5or(a int, b bool) bool {
	var x bool
	if a == 0 {
		x = true
	} else {
		x = b
	}
	return x // ERROR "converted OpPhi to OrB$"
}

//go:noinline
func f5and(a int, b bool) bool {
	var x bool
	if a == 0 {
		x = b
	} else {
		x = false
	}
	return x // ERROR "converted OpPhi to AndB$"
}

//go:noinline
func f6or(a int, b bool) bool {
	x := b
	if a == 0 {
		// f6or has side effects so the OpPhi should not be converted.
		x = f6or(a, b)
	}
	return x
}

//go:noinline
func f6and(a int, b bool) bool {
	x := b
	if a == 0 {
		// f6and has side effects so the OpPhi should not be converted.
		x = f6and(a, b)
	}
	return x
}

//go:noinline
func f7or(a bool, b bool) bool {
	return a || b // ERROR "converted OpPhi to OrB$"
}

//go:noinline
func f7and(a bool, b bool) bool {
	return a && b // ERROR "converted OpPhi to AndB$"
}

func main() {
}