Re:Can we do better than our C compiler?
by adrianN on Thursday August 13, 2020 @03:01AM
(#24140695)
"Optimal" compilation is actually harder than NP-complete. Because program equivalence is undecidable, finding a canonical "optimal" representation for a program can't be done in general.
[ Parent
| on HN ]
Re:Can we do better than our C compiler?
by programLyrique on Thursday August 13, 2020 @03:24AM
(#24140812)
What about superoptimization?
For instance, Stoke (http://stoke.stanford.edu/) or Souper (https://github.com/google/souper). They will not find all optimizations of course, and program equivalence is undecidable indeed, but they are a good shot at optimal compilation, I would say.
Re:Can we do better than our C compiler?
by adrianN on Thursday August 13, 2020 @03:41AM
(#24140907)
Just because a problem is undecidable that doesn't mean that you can't in fact solve it for a large set of interesting instances (maybe all instances you care about).
Re:Can we do better than our C compiler?
by MaxBarraclough on Thursday August 13, 2020 @04:12AM
(#24141070)
It's decidable provided the problem-space is finite, right?
Re:Can we do better than our C compiler?
by adrianN on Thursday August 13, 2020 @04:54AM
(#24141274)
Every finite problem is decidable in linear time because you can hardcode the solution.
Re:Can we do better than our C compiler?
by MaxBarraclough on Thursday August 13, 2020 @05:12AM
(#24141370)
Right, meaning decidability isn't an issue for superoptimisation of many kinds of problems.
Re:Can we do better than our C compiler?
by FartyMcFarter on Thursday August 13, 2020 @06:47AM
(#24141910)
What does that mean in practice though?
I can say that every finite computational problem can be solved in O(1), so if the universe is finite, all real problems can be solved in O(1).
This sounds great until you realise that the constant factors involved would overwhelm any practical instance of this strategy.
Re:Can we do better than our C compiler?
by MaxBarraclough on Thursday August 13, 2020 @07:05AM
(#24142021)
> What does that mean in practice though?
It means the idea isn't necessarily wholly impractical. That's not nothing.
I imagine superoptimisers scale extremely poorly, but that's a different question. I imagine they're best suited to bit-twiddling problems rather than, say, figuring out the best assembly code to implement a parallel Timsort.
I have to admit ignorance here though, I know almost nothing about superoptimisers.