3 ms·
So they finally got SSA? Neat, right up there with LLVM and GCC. It also sounds like they have something like LLVM's InstCombine pass, it'll be interesting to
by cokernel_hacker 10y ago
So they finally got SSA? Neat, right up there with LLVM and GCC.
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:
bool f() {
int x = 2;
try {
throw 0;
} catch (...) {
x = 4;
}
return x & 1;
}
Will they insert a PHI of 2 and 4?
The MSVC of today cannot optimize the return to a constant.
- cokernel_hacker 10y agoFor 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
- deleted 10y ago[deleted]
- gratilup 10y agoHi, 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!
- cokernel_hacker 10y agoCool, 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?
- gratilup 10y agoThe 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.
- inDigiNeous 10y agoFirst 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.
- cokernel_hacker 10y agoThis 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 https://en.wikipedia.org/wiki/Static_single_assignment_form for more.
- munificent 10y agoPurely a compiler hacker thing. https://en.wikipedia.org/wiki/Static_single_assignment_form https://en.wikipedia.org/wiki/Static_single_assignment_form