-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 division for positive integers #36159
Comments
cc @bmkessler |
This looks to be a limitation with prove results not being available to rewrite rules, since there are rewrite rules to handle this case:
But the implementation of
The division could be handled if the factsTable version of isNonNegative were available.
Unfortunately, the first
Currently, the prove pass only removes redundant BlockIf branches, but I don't see any reason why it shouldn't be able to make other simplifications as well. In this case, it could use the knowledge that |
Change https://golang.org/cl/212277 mentions this issue: |
I beleive the CL above fixes this issue. |
|
Yes, that is just a special case where all positive int64 are automatically less than 1<<63, so the second condition is not needed. |
Change https://golang.org/cl/232857 mentions this issue: |
What version of Go are you using (
go version
)?go version go1.13.1 windows/amd64
Does this issue reproduce with the latest release?
yes
What did you do?
What did you expect to see?
Since the variable
width
has bounds checks and is thus guaranteed to be positive, the generated code omits the extra instructions for negative numbers.In general, I prefer to write arithmetic expressions in my code instead of bit manipulations because the expressions
width/8
andwidth%8
pair up nicely. In contrast,width>>3
andwidth&7
requires more thought.What did you see instead?
The
SARQ
andSHRQ
are not necessary here.The text was updated successfully, but these errors were encountered: