aboutsummaryrefslogtreecommitdiff
path: root/test/phiopt.go
diff options
context:
space:
mode:
authorAlexandru Moșoi <mosoi@google.com>2016-04-22 12:44:31 +0200
committerAlexandru Moșoi <alexandru@mosoi.ro>2016-04-22 17:22:03 +0000
commitcaef4496fcdaca8dc5b86f60b07760e5434ca1f3 (patch)
tree40885a6f7278304ca01aa64ef3b6e221073477fa /test/phiopt.go
parent3c1a4c1902711c16489ed0c3506df97439ffbd85 (diff)
downloadgo-caef4496fcdaca8dc5b86f60b07760e5434ca1f3.tar.gz
go-caef4496fcdaca8dc5b86f60b07760e5434ca1f3.zip
cmd/compile: convert some Phis into And8.
See discussion at [1]. True value must have a fixed non-zero representation meaning that a && b can be implemented as a & b. [1] https://groups.google.com/forum/#!topic/golang-dev/xV0vPuFP9Vg This change helps with m := a && b, but it's more common to see if a && b { do something } which is not handled. Change-Id: Ib6f9ff898a0a8c05d12466e2464e4fe781035394 Reviewed-on: https://go-review.googlesource.com/22313 Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/phiopt.go')
-rw-r--r--test/phiopt.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/test/phiopt.go b/test/phiopt.go
index 37caab0b51..4347909752 100644
--- a/test/phiopt.go
+++ b/test/phiopt.go
@@ -53,23 +53,56 @@ func f4(a, b bool) bool {
}
//go:noinline
-func f5(a int, b bool) bool {
- x := b
+func f5or(a int, b bool) bool {
+ var x bool
if a == 0 {
x = true
+ } else {
+ x = b
}
return x // ERROR "converted OpPhi to Or8$"
}
//go:noinline
-func f6(a int, b bool) bool {
+func f5and(a int, b bool) bool {
+ var x bool
+ if a == 0 {
+ x = b
+ } else {
+ x = false
+ }
+ return x // ERROR "converted OpPhi to And8$"
+}
+
+//go:noinline
+func f6or(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)
+ // 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 Or8$"
+}
+
+//go:noinline
+func f7and(a bool, b bool) bool {
+ return a && b // ERROR "converted OpPhi to And8$"
+}
+
func main() {
}