summaryrefslogtreecommitdiff
path: root/test/live.go
diff options
context:
space:
mode:
authorKeith Randall <khr@google.com>2019-03-05 17:42:48 -0800
committerKeith Randall <khr@golang.org>2019-03-06 20:04:07 +0000
commit4a9064ef41ccc65454564536f40cf7d5a00db8ad (patch)
tree04eecf480d421cd19a60ddb7507b05bed5d551a0 /test/live.go
parent7778b5ab5a2215668ad1ad4d174d58b3363c9de8 (diff)
downloadgo-git-4a9064ef41ccc65454564536f40cf7d5a00db8ad.tar.gz
cmd/compile: fix ordering for short-circuiting ops
Make sure the side effects inside short-circuited operations (&& and ||) happen correctly. Before this CL, we attached the side effects to the node itself using exprInPlace. That caused other side effects in sibling expressions to get reordered with respect to the short circuit side effect. Instead, rewrite a && b like: r := a if r { r = b } That code we can keep correctly ordered with respect to other side-effects extracted from part of a big expression. exprInPlace seems generally unsafe. But this was the only case where exprInPlace is called not at the top level of an expression, so I don't think the other uses can actually trigger an issue (there can't be a sibling expression). TODO: maybe those cases don't need "in place", and we can retire that function generally. This CL needed a small tweak to the SSA generation of OIF so that the short circuit optimization still triggers. The short circuit optimization looks for triangle but not diamonds, so don't bother allocating a block if it will be empty. Go 1 benchmarks are in the noise. Fixes #30566 Change-Id: I19c04296bea63cbd6ad05f87a63b005029123610 Reviewed-on: https://go-review.googlesource.com/c/go/+/165617 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/live.go')
-rw-r--r--test/live.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/test/live.go b/test/live.go
index a508947afc..e7134eca0c 100644
--- a/test/live.go
+++ b/test/live.go
@@ -572,7 +572,7 @@ func f36() {
func f37() {
if (m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
m33[byteptr()] == 0) && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
- m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
+ m33[byteptr()] == 0 {
printnl()
return
}
@@ -697,9 +697,10 @@ func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
func f42() {
var p, q, r int
- f43([]*int{&p,&q,&r}) // ERROR "stack object .autotmp_[0-9]+ \[3\]\*int$"
- f43([]*int{&p,&r,&q})
- f43([]*int{&q,&p,&r})
+ f43([]*int{&p, &q, &r}) // ERROR "stack object .autotmp_[0-9]+ \[3\]\*int$"
+ f43([]*int{&p, &r, &q})
+ f43([]*int{&q, &p, &r})
}
+
//go:noescape
func f43(a []*int)