From f3b064ae0180461411add0aa98156dbf26f37de2 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 16 Nov 2015 10:57:07 -0800 Subject: [PATCH] cmd/compile: add 386 special case for testing first field of struct variable 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 TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/compile/internal/x86/gsubr.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/x86/gsubr.go b/src/cmd/compile/internal/x86/gsubr.go index 5127bb2cfc..03978578b7 100644 --- a/src/cmd/compile/internal/x86/gsubr.go +++ b/src/cmd/compile/internal/x86/gsubr.go @@ -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)