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: extra unused instructions for LoweredNilCheck #17211

Closed
laboger opened this issue Sep 23, 2016 · 5 comments
Closed

cmd/compile: extra unused instructions for LoweredNilCheck #17211

laboger opened this issue Sep 23, 2016 · 5 comments

Comments

@laboger
Copy link
Contributor

laboger commented Sep 23, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +dcbbd31 Thu Sep 22 06:41:11 2016 +0000 linux/ppc64le

What operating system and processor architecture are you using (go env)?

Ubuntu 16.04 ppc64le

Looking at generated code for code improvements.

This appears in many procedures and is never used (example found in runtime.c64hash):
Due to:
v26 = LoadReg <unsafe.Pointer> v8 : R3
v10 = LoweredNilCheck v26 v1

asm:
MOVB (R3), R31

With generated code:
11534: 00 00 e3 8b lbz r31,0(r3)
11538: 74 07 ff 7f extsb r31,r31

I'm not sure what it's purpose is. To avoid the extsb I believe I can just change this to a MOVD instead of a MOVB for the LoweredNilCheck, but r31 is never used in this function and the pointer for r3 is never dereferenced.

@dr2chase dr2chase self-assigned this Sep 26, 2016
@dr2chase
Copy link
Contributor

MOVB is an AMD64-ism -- PPC has no such instruction, so the assembler inserts the (unnecessary) sign extension.

@laboger
Copy link
Contributor Author

laboger commented Sep 26, 2016

But why is the load instruction even there when it is loading it into a scratch register that is never used anywhere? If a NilCheck is supposed to be checking for a nil pointer, can't it just do a compare.

@dr2chase
Copy link
Contributor

Certainly on AMD64, it's fastest to do a useless load. A branch would require a place to branch to, etc. Is there a better way for PPC?

@cherrymui
Copy link
Member

The point for this NilCheck is that if it is a nil pointer, the load will trap. You are right that the extension is unnecessary. Using MOVD would not work as it will also trap on pointer that is not 8-aligned.

@gopherbot
Copy link

CL https://golang.org/cl/29762 mentions this issue.

@golang golang locked and limited conversation to collaborators Sep 26, 2017
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