-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile/ssa: duplicate block elim #11189
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
It might be worth doing. I have 2 hesitations:
|
We could use 64-bit numbers for our hashes, and use a good hash function, and collisions would be rather improbable. I am inclined to say that we should at least code this up, maybe as a separate pass right now so that we can turn it on and off and measure its effects. I have a bee in my bonnet to look into how we do stack traces already so that we can improve our inlining story (i.e., so we can inline functions that are not inlineable all-the-way-down) and perhaps we can also concoct some better way to talk about the line numbers of commoned code. |
Oh, right. Line numbers are definitely a problem. Sigh. Thanks, @randall77. @dr2chase inlining non-leaf functions could be a significant win, if you can figure out the stack trace / profiling / etc. story to everyone's satisfaction. See #4735 and #8421 and #9337 (comment). Unless and until that gets figured out, I'm marking this as unplanned. |
The hash is tricky, and not because of the hash function itself. Use SHA256 if you want. The trick is figuring out what data to hash. Consider these two blocks: b1: b2: What do I hash here? The blocks are equivalent, but the values aren't identical. Something simple like sorting and hashing the opcodes will work, but may have lots of false positives. We'd really like to hash the "dataflow" also, whatever that means. And even if the hashes match, determining equality isn't easy. This basically boils down to a graph isomorphism problem. We have the luxury of failing if it isn't obvious, but even so I don't think it is trivial. |
cc @quasilyte -- is this a dup of your more recent work? If so, feel free to close it as wontfix. |
I've used sequential (and naive) flow comparison, so different value names were handled. The idea does sound like something I've tried to do in CL107895. For some functions, size reduction is great (can cut 20-25% of code), but for others it's close to zero. The main problem is effect on debug info (some discussion available at https://golang.org/issue/24936). |
At the end of the layout pass (chosen for readability--this remains true at the end of compilation), the SSA looks like:
Note that blocks
b3
andb5
are effectively identical. One of them could be eliminated.This happens fairly often in practice. For example, our generated equality code looks like:
This ought to produce code that is just as efficient as:
Right now it doesn't, but we can do better. There's also a lot of code in the compiler that looks like this. Also complex Less methods for sort.Interface.
Is this worth doing? Ought this to occur as part of an existing pass, or as a new one?
The text was updated successfully, but these errors were encountered: