]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add a test for writebarrier pass with single-block loop
authorCherry Zhang <cherryyz@google.com>
Tue, 14 Feb 2017 02:27:53 +0000 (21:27 -0500)
committerCherry Zhang <cherryyz@google.com>
Thu, 16 Mar 2017 14:24:52 +0000 (14:24 +0000)
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 <drchase@google.com>
src/cmd/compile/internal/ssa/writebarrier_test.go

index aaaa35a0648a6b1d984a82d5672fb3167f330031..422bc94c3f6d621b1d44229b01fff0b7ff9b18af 100644 (file)
@@ -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)
+}