From: Cherry Zhang Date: Tue, 14 Feb 2017 02:27:53 +0000 (-0500) Subject: cmd/compile: add a test for writebarrier pass with single-block loop X-Git-Tag: go1.9beta1~1146 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d75925d6bad2576bd80c442ff3b23ba22ffb2c68;p=gostls13.git cmd/compile: add a test for writebarrier pass with single-block loop The old writebarrier implementation fails to handle single-block loop where a memory Phi value depends on the write barrier store in the same block. The new implementation (CL 36834) doesn't have this problem. Add a test to ensure it. Fix #19067. Change-Id: Iab13c6817edc12be8a048d18699b4450fa7ed712 Reviewed-on: https://go-review.googlesource.com/36940 Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/ssa/writebarrier_test.go b/src/cmd/compile/internal/ssa/writebarrier_test.go index aaaa35a064..422bc94c3f 100644 --- a/src/cmd/compile/internal/ssa/writebarrier_test.go +++ b/src/cmd/compile/internal/ssa/writebarrier_test.go @@ -27,3 +27,27 @@ func TestWriteBarrierStoreOrder(t *testing.T) { writebarrier(fun.f) CheckFunc(fun.f) } + +func TestWriteBarrierPhi(t *testing.T) { + // Make sure writebarrier phase works for single-block loop, where + // a Phi op takes the store in the same block as argument. + // See issue #19067. + c := testConfig(t) + ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing + fun := Fun(c, "entry", + Bloc("entry", + Valu("start", OpInitMem, TypeMem, 0, nil), + Valu("sb", OpSB, TypeInvalid, 0, nil), + Valu("sp", OpSP, TypeInvalid, 0, nil), + Goto("loop")), + Bloc("loop", + Valu("phi", OpPhi, TypeMem, 0, nil, "start", "wb"), + Valu("v", OpConstNil, ptrType, 0, nil), + Valu("addr", OpAddr, ptrType, 0, nil, "sb"), + Valu("wb", OpStore, TypeMem, 8, ptrType, "addr", "v", "phi"), // has write barrier + Goto("loop"))) + + CheckFunc(fun.f) + writebarrier(fun.f) + CheckFunc(fun.f) +}