-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: optimize xor to complement #39710
Comments
Sure, that would work. |
Would like to suggest evaluating expressions that have more than two operands as well, like: |
Huh. If we wanted to make them interchangeable for optimization purposes, we would probably need some rules like these:
At which point I am left wondering whether the existence of |
We try to lift constants to the outermost level, and then fold them. For instance, we have these rules for xor:
Which should do the right thing for this example, at least in generic.rules. When we lower, we do need rules to combine (for amd64) NOT and XORconst. They shouldn't be hard to do. Yes, we could eliminate Com at the generic level. I'm not sure that would buy us much, as NOTs can be introduced in other ways at the arch-specific level, and thus the arch-specific rules need to know how to combine XOR and NOT anyway. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Tried to flip bits in a large section of a bitmap using
^= ^uint64(0)
in a loop.What did you expect to see?
The compiler treats this as a bitwise complement operation.
What did you see instead?
The compiler emits an xor against a constant, and treats it differently than a bitwise complement.
https://godbolt.org/z/vxQyD3
If I understand correctly, this could be solved by adding the following rule to
generic.rules
:The text was updated successfully, but these errors were encountered: