[dev.ssa] cmd/compile: fix @ rewrite rules
The @ directive used to read the target block after some value
structure had already changed. I don't think it was ever really
a bug, but it's confusing.
It might fail like this:
(Foo x y) -> @v.Args[0].Block (Bar y (Baz ...))
v.Op = Bar
v.Args[0] = y
v.Args[1] = v.Args[0].Block.NewValue(Baz, ...)
That new value is allocated in the block of y, not the
block of x.
Anyway, read the destination block first so this
potential bug can't happen.
Change-Id: Ie41d2fc349b35cefaa319fa9327808bcb781b4e2
Reviewed-on: https://go-review.googlesource.com/19900
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go
index 08ab2e1..4f29cf5 100644
--- a/src/cmd/compile/internal/ssa/rewritegeneric.go
+++ b/src/cmd/compile/internal/ssa/rewritegeneric.go
@@ -7102,10 +7102,13 @@
if !(!config.fe.CanSSA(t)) {
break
}
- v0 := v.Args[0].Block.NewValue0(v.Line, OpLoad, v.Type)
+ b = v.Args[0].Block
+ v0 := b.NewValue0(v.Line, OpLoad, v.Type)
v.reset(OpCopy)
v.AddArg(v0)
- v1 := v.Args[0].Block.NewValue0(v.Line, OpOffPtr, v.Type.PtrTo())
+ v1 := b.NewValue0(v.Line, OpOffPtr, v.Type.PtrTo())
+ v.reset(OpCopy)
+ v.AddArg(v1)
v1.AuxInt = t.FieldOff(i)
v1.AddArg(ptr)
v0.AddArg(v1)