aboutsummaryrefslogtreecommitdiff
path: root/test/phiopt.go
diff options
context:
space:
mode:
authorAlexandru Moșoi <mosoi@google.com>2016-04-12 18:24:34 +0200
committerAlexandru Moșoi <alexandru@mosoi.ro>2016-04-19 22:04:30 +0000
commit8b20fd000d7e894865442134f9d6d197ac5dabed (patch)
tree29c90352d4da834de0b9c12bcdb3d5e31fdd8652 /test/phiopt.go
parent082f464823cdb47042a142802776fa7874e6c05b (diff)
downloadgo-8b20fd000d7e894865442134f9d6d197ac5dabed.tar.gz
go-8b20fd000d7e894865442134f9d6d197ac5dabed.zip
cmd/compile: transform some Phis into Or8.
func f(a, b bool) bool { return a || b } is now a single instructions (excluding loading and unloading the arguments): v10 = ORB <bool> v11 v12 : AX Change-Id: Iff63399410cb46909f4318ea1c3f45a029f4aa5e Reviewed-on: https://go-review.googlesource.com/21872 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'test/phiopt.go')
-rw-r--r--test/phiopt.go40
1 files changed, 36 insertions, 4 deletions
diff --git a/test/phiopt.go b/test/phiopt.go
index 9b9b701124..37caab0b51 100644
--- a/test/phiopt.go
+++ b/test/phiopt.go
@@ -1,8 +1,13 @@
// +build amd64
// 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 {
@@ -10,9 +15,10 @@ func f0(a bool) bool {
} else {
x = false
}
- return x // ERROR "converted OpPhi to OpCopy$"
+ return x // ERROR "converted OpPhi to Copy$"
}
+//go:noinline
func f1(a bool) bool {
x := false
if a {
@@ -20,23 +26,49 @@ func f1(a bool) bool {
} else {
x = true
}
- return x // ERROR "converted OpPhi to OpNot$"
+ 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 OpNot$"
+ 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 OpCopy$"
+ return x // ERROR "converted OpPhi to Copy$"
+}
+
+//go:noinline
+func f4(a, b bool) bool {
+ return a || b // ERROR "converted OpPhi to Or8$"
+}
+
+//go:noinline
+func f5(a int, b bool) bool {
+ x := b
+ if a == 0 {
+ x = true
+ }
+ return x // ERROR "converted OpPhi to Or8$"
+}
+
+//go:noinline
+func f6(a int, b bool) bool {
+ x := b
+ if a == 0 {
+ // f6 has side effects so the OpPhi should not be converted.
+ x = f6(a, b)
+ }
+ return x
}
func main() {