[PATCH] Added llvm.is.constant intrinsic

Nick Lewycky nlewycky at google.com
Sat Jun 28 00:37:37 PDT 2014


On 27 June 2014 08:28, Sobczak, Janusz <janusz.sobczak at mobica.com> wrote:

> 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.
>

I wish I'd written down how builtin_constant_p is supposed to behave from
last time I tangoed with it. I think the rule is that it decides whether a
pointer is constant early, and whether an integer is constant after later
optimization. I may have those two reversed. +cc Richard Smith who may
recall.

I'm attaching the test I wrote for it. Note that gcc gives different
answers at different optimization levels, and again if you move the globals
into being function-local variables.

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.*
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140628/59c1eccb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bcp.c
Type: text/x-csrc
Size: 5271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140628/59c1eccb/attachment.c>


More information about the llvm-commits mailing list