[LLVMdev] precondition suggestion to LLVM

Philip Reames listmail at philipreames.com
Tue Oct 23 15:28:02 PDT 2012


(Apologies if anyone gets duplicates.  Resending as 4.5 hours after 
sending, I haven't seen this come through.)

Niko,

There are a number of folks interested in similar things, but to my 
knowledge nothing has been added to LLVM to explicitly support this use 
case (yet).  Using an unreachable instruction is a good starting point, 
but as mentioned by David, we prune these too early at this point in time.

If you're interested, I've got a hacky implementation which works around 
the problem by inserting a dummy function, running all passes, dropping 
the dummy function, and rerunning optimizations.  I just posted the code 
on github[1], but - fair warning - this is basically untested at this 
point.  I've run a couple of toy examples, but that's about it.

Yours,
Philip Reames


[1] https://github.com/preames/llvm-assume-hack

On 10/22/2012 09:40 PM, David Blaikie wrote:
> On Mon, Oct 22, 2012 at 9:33 PM, Niko Zarzani <koni10 at hotmail.it> wrote:
>> Thank you, it was what I really was searching for :)
>>
>> However, I don't know if I well understood. I've find this link in the
>> second link which seemed what i was looking for:
>> http://nondot.org/sabre/LLVMNotes/BuiltinUnreachable.txt .
>> If I put around the code block (inside my function with precondition (x>0 &&
>> y>0)) a contruct like that that use __builtin_unreachable:
>>
>> int foo(int x, int y){
>>
>>     if(x>0 && y>0){
>>         ...function codeblock...
>>     }
>>     {
>>        __builtin_unreachable ();
>>     }
>>
>> }
>>
>> I can get the optimization without really having a branch jump in the
>> machine code?
>
> In theory, yes - in practice, we eliminate unreachable blocks too
> early for any real optimization to occur on the basis of this branch
> to unreachable. More details here:
> http://llvm.org/bugs/show_bug.cgi?id=810
>
>> Thank you again,
>>
>> Niko Zarzani
>>
>>> Date: Mon, 22 Oct 2012 23:41:43 -0400
>>> From: xi.wang at gmail.com
>>> To: koni10 at hotmail.it
>>> CC: llvmdev at cs.uiuc.edu
>>
>>> Subject: Re: [LLVMdev] precondition suggestion to LLVM
>>>
>>> You may want to check this out:
>>>
>>> http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-October/053924.html
>>>
>>> and also
>>>
>>> http://llvm.org/PR810
>>>
>>> - xi
>>>
>>> On 10/22/12 6:05 PM, Niko Zarzani wrote:
>>>> Hi all,
>>>> Is there any way to tell LLVM some additional information about the
>>>> variables in the code in order to make better optimization?
>>>> For example, if my function has a certain precondition (such as x>0)
>>>> then it will be possible to better optimize the code given that
>>>> information (which the compiler does not know).
>>>> I am new in this field and I don't know if there are ways to tell the
>>>> compiler preconditions (such as by using some preprocessing directives).
>>>> Thank you in advance,
>>>> Niko Zarzani
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



More information about the llvm-dev mailing list