<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On 28 June 2014 09:37, Nick Lewycky <span dir="ltr"><<a href="mailto:nlewycky@google.com" target="_blank">nlewycky@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="">On 27 June 2014 08:28, Sobczak, Janusz <span dir="ltr"><<a href="mailto:janusz.sobczak@mobica.com" target="_blank">janusz.sobczak@mobica.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>On 27 June 2014 09:18, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br>


</div><div class="gmail_extra"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>Rafael Avila de Espindola wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Ccing nick since it seems related to the enable_if attribute.<br>
</blockquote>
<br></div>
Surely not? attribute enable_if is defined entirely in language terms.<br>
<br>
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.<span><font color="#888888"><br>



</font></span></blockquote><div><br></div></div><div>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:<br>



int inline __attribute__((always_inline)) fun(int x) {<br>    return __builtin_constant_p(x);<br>}<br><br>int main() {<br>    return fun(0);<br>}<br><br></div><div>This example will return 1 if compiled with gcc but it will return 0 if compiled with clang.<br>


</div></div></div></div></blockquote><div><br></div></div><div>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.</div>


<div><br></div><div>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.</div><div><div class="h5">
<div><br></div></div></div></div></div></div></blockquote><div><br></div><div>I'm thinking about modyfing __builtin_constant_p() implementation in clang to do this (for integer arguments):<br></div><div>if (argument is known to be constant)<br>
</div><div>    replace  __builtin_constant_p() with 1 (True)<br></div><div>else<br></div><div>   replace __builtin_constant_p() with @llvm.is_constant() IR<br></div><div> <br></div></div>-- <br><div dir="ltr">Janusz Sobczak<br>
Mobica Ltd<br><a href="http://www.mobica.com" target="_blank">www.mobica.com</a> <<a href="http://www.mobica.com" target="_blank">http://www.mobica.com</a>><br><br><br>*Mobica is a provider of software engineering, testing and consultancy <br>
services based in the UK, Poland and the USA, with a worldwide customer <br>base. We have a proven track record in delivering innovative solutions to <br>some of the world’s best-known companies in a range of sectors including <br>
Automotive, Mobile, Semiconductor, Finance, TV, Marine and Aviation.*<br><br></div>
</div></div>