The offending rule could move the load to a different block,
which is always a bad idea.
Fixes #22683
Change-Id: I973c88389b2359f734924d9f45c3fb38e166691d
Reviewed-on: https://go-review.googlesource.com/77331
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
(Store _ (ArrayMake0) mem) -> mem
(Store dst (ArrayMake1 e) mem) -> (Store {e.Type} dst e mem)
-(ArraySelect [0] (Load ptr mem)) -> (Load ptr mem)
+(ArraySelect [0] x:(Load ptr mem)) -> @x.Block (Load <v.Type> ptr mem)
// Putting [1]{*byte} and similar into direct interfaces.
(IMake typ (ArrayMake1 val)) -> (IMake typ val)
return false
}
func rewriteValuegeneric_OpArraySelect_0(v *Value) bool {
+ b := v.Block
+ _ = b
// match: (ArraySelect (ArrayMake1 x))
// cond:
// result: x
v.AddArg(x)
return true
}
- // match: (ArraySelect [0] (Load ptr mem))
+ // match: (ArraySelect [0] x:(Load ptr mem))
// cond:
- // result: (Load ptr mem)
+ // result: @x.Block (Load <v.Type> ptr mem)
for {
if v.AuxInt != 0 {
break
}
- v_0 := v.Args[0]
- if v_0.Op != OpLoad {
+ x := v.Args[0]
+ if x.Op != OpLoad {
break
}
- _ = v_0.Args[1]
- ptr := v_0.Args[0]
- mem := v_0.Args[1]
- v.reset(OpLoad)
- v.AddArg(ptr)
- v.AddArg(mem)
+ _ = x.Args[1]
+ ptr := x.Args[0]
+ mem := x.Args[1]
+ b = x.Block
+ v0 := b.NewValue0(v.Pos, OpLoad, v.Type)
+ v.reset(OpCopy)
+ v.AddArg(v0)
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
return true
}
// match: (ArraySelect [0] x:(IData _))
--- /dev/null
+// cmpout
+
+// Copyright 2017 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
+
+import (
+ "fmt"
+)
+
+type foo struct {
+ bar [1]*int
+}
+
+func main() {
+ ch := make(chan foo, 2)
+ var a int
+ var b [1]*int
+ b[0] = &a
+ ch <- foo{bar: b}
+ close(ch)
+
+ for v := range ch {
+ for i := 0; i < 1; i++ {
+ fmt.Println(v.bar[0] != nil)
+ }
+ }
+}