[cfe-dev] Avoiding removal of a builtin call

Philip Reames listmail at philipreames.com
Tue May 20 10:21:37 PDT 2014


More generally, we don't have a way to model non-memory side effects.  
Having such a mechanism might be useful to avoid polluting alias results 
for such builtins.

We have a similar case out of tree which we ended up solving by 
converting a void function to a value returning function and then 
(volatile) storing the result to a known location.  This feels like 
somewhat of a hack, but does have the advantage of working and not 
preventing most aliasing based optimizations.  :)

Philip

On 05/20/2014 09:40 AM, Rafael EspĂ­ndola wrote:
> The problem I think is that llvm.write_register.i64 is being marked
> readnone. We don't have physical registers as first class items in
> llvm, so as a small hack we probably need to have doesNotAccessMemory
> return false for llvm.write_register (i.e., don't add ReadNone to it).
>
> On 20 May 2014 09:57, Renato Golin <renato.golin at linaro.org> wrote:
>> Hi Reid, Rafael,
>>
>> I'm having trouble keeping the call to @llvm.write_register() in the
>> IR on higher levels of optimization.
>>
>> At O0:
>>
>> define void @set_stack_pointer_addr(i64 %addr) #0 {
>> entry:
>>    %addr.addr = alloca i64, align 8
>>    store i64 %addr, i64* %addr.addr, align 8
>>    %0 = load i64* %addr.addr, align 8
>>    call void @llvm.write_register.i64(metadata !0, i64 %0)
>>    ret void
>> }
>>
>> At O1:
>>
>> define void @set_stack_pointer_addr(i64 %addr) #0 {
>> entry:
>>    ret void
>> }
>>
>> I tried marking the function (or the call) with "builtin" attribute,
>> but the validation fails:
>>
>> Attribute 'builtin' only applies to functions!
>> void (metadata, i64)* @llvm.write_register.i64
>> Attribute 'builtin' only applies to functions!
>> call builtin void @llvm.write_register.i64(metadata !0, i64 %0)
>>
>> Is there a way to avoid that call from being removed without marking
>> the symbol as extern or other tricks?
>>
>> cheers,
>> --renato
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list