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/internal/obj: remove MOV $0 -> XOR "optimization" #22325

Closed
aclements opened this issue Oct 18, 2017 · 2 comments
Closed

cmd/internal/obj: remove MOV $0 -> XOR "optimization" #22325

aclements opened this issue Oct 18, 2017 · 2 comments

Comments

@aclements
Copy link
Member

Currently cmd/internal/obj replaces MOV* $0, r with XOR* r, r for 386 and amd64 as an "optimization". However, this is not a semantics-preserving transformation since XOR clobbers registers, while MOV does not.

This has caused pain in several places:

  1. The compiler sets a special PRESERVEFLAGS bit when it creates MOV Progs at points where the flags are live.

  2. The assembly in math/big has the ominous comment "CAUTION: Note that MOVQ $0, Rx is translated to XORQ Rx, Rx which clears the carry bit!".

  3. It caused bugs in CL 71270 that were very difficult to track down and required restructuring the assembly to work around.

We should consider removing this transformation from obj and instead just doing it in the compiler. There are only a handful of instances of this in hand-written assembly in the standard library. We could rewrite these to XOR by hand, or just not bother.

/cc @randall77 @iant

@ALTree
Copy link
Member

ALTree commented Oct 18, 2017

This is #20986.

@aclements
Copy link
Member Author

Closing as dup of #20986 (which I've just added some info to).

@golang golang locked and limited conversation to collaborators Oct 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

3 participants