Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: unnecessary nil check after store #19148

Closed
mundaym opened this issue Feb 17, 2017 · 3 comments
Closed

cmd/compile: unnecessary nil check after store #19148

mundaym opened this issue Feb 17, 2017 · 3 comments

Comments

@mundaym
Copy link
Member

mundaym commented Feb 17, 2017

At tip (79f6a5c) it looks like nil checks don't always get eliminated when a load that follows a store is eliminated. Not sure if this is a known issue:

//go:noinline
func loadHitStore8(x int8, p *int8) int32 {
       x *= x
       *p = x
       return int32(*p)
}

compiles to (on amd64):

TEXT	"".loadHitStore8(SB)
FUNCDATA	$0, "".gcargs·16(SB)
FUNCDATA	$1, "".gclocals·17(SB)
MOVBLZX	"".x(FP), AX
IMULL	AX, AX
MOVQ	"".p+8(FP), CX
MOVB	AX, (CX)
TESTB	AX, (CX) // <------------- unnecessary nil check after store
VARDEF	"".~r2+16(FP)
MOVBQSX	AX, AX
MOVL	AX, "".~r2+16(FP)
RET

I see a similar issue on s390x.

@mundaym mundaym changed the title cmd/compile: unnecessary bounds check after store cmd/compile: unnecessary nil check after store Feb 17, 2017
@randall77
Copy link
Contributor

See #18725 , I think the fix for that bug caused this to happen. The problem is the two nil checks are in the same block and the values in a block are unordered during nil check elim.

Might be fixed by https://go-review.googlesource.com/c/35496/

@cherrymui
Copy link
Member

Yes, CL https://go-review.googlesource.com/c/35496/ fixes it. With the CL applied, it generates

"".loadHitStore8 t=1 size=24 args=0x18 locals=0x0
	0x0000 00000 (/tmp/x.go:4)	TEXT	"".loadHitStore8(SB), $0-24
	0x0000 00000 (/tmp/x.go:4)	FUNCDATA	$0, gclocals·209db2785ac68f3647faf623a4cc45e7(SB)
	0x0000 00000 (/tmp/x.go:4)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x0000 00000 (/tmp/x.go:5)	MOVBLZX	"".x+8(FP), AX
	0x0005 00005 (/tmp/x.go:5)	IMULL	AX, AX
	0x0008 00008 (/tmp/x.go:6)	MOVQ	"".p+16(FP), CX
	0x000d 00013 (/tmp/x.go:6)	MOVB	AL, (CX)
	0x000f 00015 (/tmp/x.go:7)	MOVBQSX	AL, AX
	0x0013 00019 (/tmp/x.go:7)	MOVL	AX, "".~r2+24(FP)
	0x0017 00023 (/tmp/x.go:7)	RET

@cherrymui
Copy link
Member

CL https://go-review.googlesource.com/c/35496/ is submitted. Closing.

@golang golang locked and limited conversation to collaborators Feb 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants