]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add 386 special case for testing first field of struct variable
authorIan Lance Taylor <iant@golang.org>
Mon, 16 Nov 2015 18:57:07 +0000 (10:57 -0800)
committerIan Lance Taylor <iant@golang.org>
Sun, 29 Nov 2015 16:56:03 +0000 (16:56 +0000)
This is the 386 version of the amd64-specific https://golang.org/cl/16933.

Update #12416.

Change-Id: Ibc3a99dcc753d6281839d8b61016d6c21dbd9649
Reviewed-on: https://go-review.googlesource.com/16970
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/x86/gsubr.go

index 5127bb2cfc56844961147cc813113c45bfb44170..03978578b7575a0addef14fda2451138fa61978c 100644 (file)
@@ -635,7 +635,15 @@ func ginscmp(op gc.Op, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog {
 
        // General case.
        var r1, r2, g1, g2 gc.Node
-       if n1.Op == gc.ONAME && n1.Class&gc.PHEAP == 0 || n1.Op == gc.OINDREG {
+
+       // A special case to make write barriers more efficient.
+       // Comparing the first field of a named struct can be done directly.
+       base := n1
+       if n1.Op == gc.ODOT && n1.Left.Type.Etype == gc.TSTRUCT && n1.Left.Type.Type.Sym == n1.Right.Sym {
+               base = n1.Left
+       }
+
+       if base.Op == gc.ONAME && base.Class&gc.PHEAP == 0 || n1.Op == gc.OINDREG {
                r1 = *n1
        } else {
                gc.Regalloc(&r1, t, n1)