[PATCH] Added llvm.is.constant intrinsic

Sobczak, Janusz janusz.sobczak at mobica.com
Fri Jun 27 08:28:34 PDT 2014


On 27 June 2014 09:18, Nick Lewycky <nicholas at mxc.ca> wrote:

> Rafael Avila de Espindola wrote:
>
>>
>> Ccing nick since it seems related to the enable_if attribute.
>>
>
> Surely not? attribute enable_if is defined entirely in language terms.
>
> I don't see it in LangRef but I thought we already had @llvm.is.constant
> to implement __builtin_constant_p in the middle-end? If I'm remembering
> right then what we should do is try to match gcc's behaviour.
>

Currently, __builtin_constant_p() is lowered to true/false in clang. Adding
this intrinsic (and using it in clang) will allow the compiler to optimise
the following code:
int inline __attribute__((always_inline)) fun(int x) {
    return __builtin_constant_p(x);
}

int main() {
    return fun(0);
}

This example will return 1 if compiled with gcc but it will return 0 if
compiled with clang.


> Nick
>
>
>  On Jun 25, 2014, at 11:22, Janusz Sobczak<janusz.sobczak at mobica.com>
>>>  wrote:
>>>
>>> ================
>>> Comment at: test/CodeGen/Generic/inline-is-constant.ll:4
>>> @@ +3,3 @@
>>> +; Expected outcome: @fun is inlined and @llvm.is.constant is resolved
>>> to TRUE
>>> +; Without inlining @llvm.is.constant would resolve to FALSE.
>>> +
>>> ----------------
>>> Renato Golin wrote:
>>>
>>>> a more robust way would be to have two run lines, one with O0, another
>>>> with O3, and use FileCheck for the True/False results.
>>>>
>>> If using lli is frowned upon, then the resolution is to call 'llc
>>> -debug' and search for the debug strings with FileCheck
>>>
>>> http://reviews.llvm.org/D4276
>>>
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>


-- 
Janusz Sobczak
Mobica Ltd
www.mobica.com <http://www.mobica.com>


*Mobica is a provider of software engineering, testing and consultancy
services based in the UK, Poland and the USA, with a worldwide customer
base. We have a proven track record in delivering innovative solutions to
some of the world’s best-known companies in a range of sectors including
Automotive, Mobile, Semiconductor, Finance, TV, Marine and Aviation.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140627/eefca5e2/attachment.html>


More information about the llvm-commits mailing list