1
0
mirror of https://github.com/golang/go synced 2024-11-23 12:20:12 -07:00
go/test/phiopt.go
Alexandru Moșoi 8b20fd000d 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>
2016-04-19 22:04:30 +00:00

76 lines
1.1 KiB
Go

// +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 {
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 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() {
}