r199302 - CodeGen: Simplify CodeGenFunction::EmitCaseStmt

Justin Bogner mail at justinbogner.com
Wed Jan 15 00:21:52 PST 2014


Chandler Carruth <chandlerc at google.com> writes:
> On Tue, Jan 14, 2014 at 11:30 PM, Justin Bogner <mail at justinbogner.com> wrote:
>
>     Author: bogner
>     Date: Wed Jan 15 01:30:30 2014
>     New Revision: 199302
>    
>     URL: http://llvm.org/viewvc/llvm-project?rev=199302&view=rev
>     Log:
>     CodeGen: Simplify CodeGenFunction::EmitCaseStmt
>    
>     Way back in r129652 we tried to avoid emitting an empty block at -O0
>     for switch cases that did nothing but break. This led to a poor
>     debugging experience as reported in PR9796, so we disabled the
>     optimization for -O0 but left it in for higher optimization levels in
>     r154420.
>    
>     Since the whole point of this was to improve -O0, it's silly to keep
>     the complexity at all.
>
> Hold on, I don't think that's the right way to interpret this.
>
> Allocating, wiring up, optimizing and deleting the block all have very
> non-trivial compile-time cost. They introduce guaranteed malloc traffic.
> Worse, linear amounts of malloc traffic.

I hadn't thought about this point, but as far as "how this came to be" I
don't think that there's any other way to interpret it. r129652
specifically calls this "a -O0 code quality issue" in its commit
message.

>From a programmer's perspective, letting the backend clean up these
blocks means less duplicated logic, and in my experience that means
fewer bugs. That said, I don't have a deep understanding of the cost for
the backend to remove empty blocks.

> It seems very worth a small amount of complexity in clang to emit more minimal
> IR. While I'm OK keeping these blocks when we need them (for whatever reason,
> debugging, profiling, whatever), I don't think we should unilaterally keep
> them.
>
> I can move the discussion to the code review thread if you'd like, but this
> commit seemed to take things a significant step further than was discussed in
> that thread by *always* keeping these blocks.

The conversation about this block of code started with "Is it really
worth that much for code gen/optimization time to not just always have
it?". I don't think it's fair to say this commit goes any further than
answering "no" to that question. Nonetheless, that might not be the
right answer, depending on the actual cost of llvm CodeGen and the
frequency of do-nothing switch cases.



More information about the cfe-commits mailing list