[LLVMdev] C as used/implemented in practice: analysis of responses

Daniel Berlin dberlin at dberlin.org
Thu Jul 2 15:36:20 PDT 2015

On Wed, Jul 1, 2015 at 7:20 AM, Russell Wallace
<russell.wallace at gmail.com> wrote:
> On Tue, Jun 30, 2015 at 6:21 PM, Hal Finkel <hfinkel at anl.gov> wrote:
>> We exploit undefined behavior because it helps to optimize real programs
>> and shrink the size of generated code.
> That is the reason compilers exploit undefined behaviour even when they are
> generating code for a vanilla architecture with a flat address space, yes.
> However, I will suggest:
> 1. The performance gain from this on real programs is small. I will suggest
> that the total performance gain from optimisations that rely on exploiting
> undefined behaviour - let's call them monkey's paw optimisations for short -
> is practically never more than a few percent, and often less than one
> percent.

This is a very large assumption.

If you mean "direct optimization based on undef", it may be correct.
If you mean "optimization that takes advantage of knowledge of what
undefined behavior is", this is surely wrong.

Almost all loop analysis/etc takes advantage of knowing what both
implementation and undefined behavior is to be able to do simple
things like "derive loop bounds" for most loops, let alone more
advanced things.

More information about the llvm-dev mailing list