-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
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:
-
The compiler sets a special PRESERVEFLAGS bit when it creates MOV Progs at points where the flags are live.
-
The assembly in
math/bighas the ominous comment "CAUTION: Note that MOVQ $0, Rx is translated to XORQ Rx, Rx which clears the carry bit!". -
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