[LLVMdev] Helping the optimizer along (__assume)

Gordon Henriksen gordonhenriksen at me.com
Wed Oct 22 17:36:04 PDT 2008


On 2008-10-22, at 19:24, Mike Stump wrote:

> On Oct 22, 2008, at 3:28 PM, Paul Biggar wrote:
>
>> As part of our PHP compiler (phpcompiler.org), it would be great to  
>> be able to annotate our generated C code with, for example, (var !=  
>> NULL), or (var->type == STRING), and have that information passed  
>> around (esp interprocedurally at link-time) by the LLVM optimizers.
>
> For some odd reason I was thinking this was going to be done with an  
> assert (or a special no code generating assert).  Just gen up assert  
> (i != 0); and put it in anytime it is true.  The optimizers in the  
> fulness of time would the recognize and propagate this information.

Can't you implement __builtin_assume(cond) to codegen to something like:

	%cond = i1 ...
	br i1 %cond, label %always, label %never
never:
	unreachable
always:

Then in assert.h:

#ifdef NDEBUG
#  define assert(cond) __builtin_assume((cond))
#else
#  define assert(cond) ...
#endif

— Gordon





More information about the llvm-dev mailing list