Re:Introducing a new, advanced Visual C++ code optimizer
by gratilup on Thursday May 05, 2016 @04:48PM
(#11639561)
Hi,
I'm the author of the blog post and optimizer. We had SSA since around 1999-2000, just that some important components like the expression optimizer were written before that and not updated with support for SSA. The difference is a lot more than just SSA, the blog has just a few examples. The new framework started as being somewhat similar to InstCombine, since then it got much larger and it will be the place where more optimizations will be integrated, hopefully replacing some older ones. To answer your question: SSA is built with both types of exceptions and the new optimizer works as expected, except a few cases where it would be unsafe. It seems that the rejection rules are a bit too aggressive in your example, it's obviously safe to optimize in this case - thanks for the example!
Re:Introducing a new, advanced Visual C++ code optimizer
by cokernel_hacker on Thursday May 05, 2016 @05:11PM
(#11639684)
Cool, good to know!
Another interesting example is:
bool f(bool b) {
int x;
try {
if (b) {
x = 2;
throw 0;
}
x = 4;
throw 0.0;
} catch (...) {
}
return x & 1;
}
Here, a phi is needed on the catch.Out of curiosity, can you give details regarding how your EH representation looks like in SSA?
Re:Introducing a new, advanced Visual C++ code optimizer
by gratilup on Sunday May 08, 2016 @04:37PM
(#11655681)
The EH info looks the same when in SSA form - when building SSA the right PHIs are inserted for the values potentially defined in EH blocks.
Re:Introducing a new, advanced Visual C++ code optimizer
by cokernel_hacker on Thursday May 05, 2016 @03:48PM
(#11639162)
For reference, clang targeting MSVC mode can do this:
$ clang t.cpp -target x86_64-pc-win32 -S -emit-llvm -o - | opt -S -sroa -instcombine | grep 'ret i1'
ret i1 false
Re:Introducing a new, advanced Visual C++ code optimizer
by inDigiNeous on Thursday May 05, 2016 @06:44PM
(#11640245)
First time I'm hearing about SSA. Is it something me as a coder should be thinking about while writing code, or is it purely a compiler phase ? Thanks.
Re:Introducing a new, advanced Visual C++ code optimizer
by cokernel_hacker on Thursday May 05, 2016 @07:07PM
(#11640387)
This is not something you should think about writing code. Unless that code comprises a compiler :)
SSA is a program representation which is easy for compilers to analyze and optimize. See https://en.wikipedia.org/wiki/Static_single_assignment_form for more.
Re:Introducing a new, advanced Visual C++ code optimizer
by munificent on Thursday May 05, 2016 @07:09PM
(#11640400)
Purely a compiler hacker thing.
It also sounds like they have something like LLVM's InstCombine pass, it'll be interesting to compare which cases they handle. Despite it being a peephole pass, InstCombine is actually one of the most important scalar optimizations in LLVM's arsenal.
I also wonder if they form SSA in the face of C++ and/or SEH exceptions.
Like if you have something like:
Will they insert a PHI of 2 and 4? The MSVC of today cannot optimize the return to a constant.