-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: MOV $0, r to XOR r, r rewrite is unsafe #12405
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
Comments
I am not convinced. "MOV" is a pseudo-operation in the Go assembler. It is NOT just one instruction. XOR is one possible implementation of that pseudo-operation. Therefore SSA should expect that MOV can affect flags. |
Yes, that was our fix, marking MOVx as clobbering flags. Even though most of the time it won't. |
MOV is the main one. I know that's not terribly precise. Eventually we'll have a formal statement of all this that you could just look at. |
Anyway, sounds like this got fixed. |
The x86 backend automatically rewrites MOV $0, AX to XOR AX, AX. That rewrite isn't ok when the flags register is live across the MOV. Keep track of which moves care about preserving flags, then disable this rewrite for them. On x86, Prog.Mark was being used to hold the length of the instruction. We already store that in Prog.Isize, so no need to store it in Prog.Mark also. This frees up Prog.Mark to hold a bitmask on x86 just like all the other architectures. Update #12405 Change-Id: Ibad8a8f41fc6222bec1e4904221887d3cc3ca029 Reviewed-on: https://go-review.googlesource.com/18861 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
liblink rewrites
MOV $0, r
toXOR r, r
. MOV does not impact flags, but XOR does. As a result, this rewrite is not generally safe. This was the source of a bug in the SSA branch (see CL 14042 and 14043). It could also impact hand-written assembly. It is an accident of the current backend codegen that it doesn't cause bugs now.We should remove the liblink rewrite and generate
XOR r, r
directly if/when that is desired. For example, for the existing backend, this could become part of the peephole optimizer; we can update the existing handwritten assembly.cc @bradfitz @tzneal @randall77
The text was updated successfully, but these errors were encountered: