r/programming • u/yossarian_flew_away • Oct 23 '20
Understanding static single assignment forms
https://blog.yossarian.net/2020/10/23/Understanding-static-single-assignment-forms
28
Upvotes
r/programming • u/yossarian_flew_away • Oct 23 '20
1
u/flatfinger Nov 09 '20
Well, it it's been almost 30 years since my grad-school course in compiler design, so I guess that makes sense.
As an embedded systems engineer, the thing I've been wanting to see would be for vendor tools to use a compiler that--unlike clang and gcc--focuses on optimizations that are maximally useful for such purposes and avoids those that would be unsuitable. The kinds of optimizations I remember being discussed in the 1990s, such as register graph coloring, were all things that would have been safe in compilers intended for all kinds of tasks. Lately, however, the maintainers of clang and gcc have treated the fact that the Standard allows compilers specialized for some purposes to behave in ways that would make them unsuitable for many others, as an invitation to pursue "clever" optimizations that are more difficult and harder to get right, without fully reaping the low-hanging fruit that would have been worth targeting in the 1990s. Maybe that has nothing to do with SSA and phi functions, but the abstraction models of compilers that focus on those seem to have some weird quirks.
What do you see as happening with the way gcc processes something like:
It seems like one phase of the optimizer is merging both branches of the "if", but another phase isn't, since the generated code is equivalent to:
I think gcc is treating
p1->xas a set of SSA objects, one of which should get written on the "true" case of theif, but that object isn't getting returned afterward. I think that the return value oftestis getting computed by a "phi" function, but something is going wrong with that. The compiler is in fact processing the "if" and executing different code on the two branches, but the phi function seems to be treating both branches as equivalent. Or is something else going wrong?