-
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: teach prove pass that x|1 > 0 for unsigned x #46444
Comments
Not sure about the prove pass. Might be easiest in the section where we find length and capacity ops. When you find v=(OR x (CONST c)) add f.update(b, v, c, unsigned, gt|eq). It might be easier just to do, in generic.rules
But then maybe you also want to handle |
Thanks! Given that this is fairly specialized, doing it all in rewrite rules makes sense. |
Implemented. Surprisingly, it made performance worse. |
What was your benchmark? |
@dr2chase have found this issue from this repo https://github.com/josharian/log10 and probably here is the mentioned benchmark https://github.com/josharian/log10/blob/main/log10_test.go#L114 |
Thanks, @cristaloleg. That's the benchmark, plus some minor variations that I was experimenting with. (I no longer have the exact code in front of me, but IIRC they are the obvious changes you might toy with trying to get good generated code out of those functions.) The rules I added to experiment with were in AMD64.rules:
and generic.rules:
This made the generated code shorter, but slower. I also added these to AMD64.rules, which generated better code, including one or two other places in the standard library:
I didn't mail these because I was frustrated that the failed to capture many of the cases in which we could use ADCQ. The problem is that we canonicalize many |
Compiles to:
Instead of the LEAQ/LEAQ/BSRQ triple of instructions, it should be a single BSRL.
There are two parts to this.
Part one is introducing OpBitLenNNNonZero ops, much as we have OpCtzNNNonZero ops, and hooking them up appropriately. This is easy.
Part two is teaching the prove pass that unsigned x|1 > 0.
Seems like it should be a simple thing to teach it, but I always get lost in the prove pass. Any hints?
cc @zdjones @dr2chase @randall77
The text was updated successfully, but these errors were encountered: