<html><body><p><font size="2">Thanks, Chandler.  I have forwarded it to cfe-dev.</font><br><br><font size="2">Thanks.</font><br><br><font size="2">BRS//</font><br><font size="2">Chen Zheng</font><br><font size="2">Power Compiler Backend Developer</font><br><br><br><img width="16" height="16" src="cid:1__=C7BB0916DFD062C88f9e8a93df938690918cC7B@" border="0" alt="Inactive hide details for Chandler Carruth ---2019/01/16 12:20:23 PM---This isn't really a discussion about LLVM any longer. LL"><font size="2" color="#424282">Chandler Carruth ---2019/01/16 12:20:23 PM---This isn't really a discussion about LLVM any longer. LLVM has the ability to model pointer paramete</font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Chandler Carruth <chandlerc@gmail.com></font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">Zheng CZ Chen <czhengsz@cn.ibm.com></font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">Troy Johnson <troyj@cray.com>, "Finkel, Hal J." <hfinkel@anl.gov>, Roman Lebedev <lebedev.ri@gmail.com>, "llvm-dev@lists.llvm.org" <llvm-dev@lists.llvm.org></font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">2019/01/16 12:20 PM</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [llvm-dev] Aggressive optimization opportunity</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br>This isn't really a discussion about LLVM any longer. LLVM has the ability to model pointer parameters with the desired semantics.<br><br>This is now a question about a C/C++ extension to Clang. That discussion would probably be best held on cfe-dev where there are more folks focused on the language and frontend. My suspicion is that there will be very little desire for an extension that knowingly and intentionally breaks very basic properties of C and C++, but it may be worth asking the correct audience that question. =]<br><br>On Tue, Jan 15, 2019 at 6:57 PM Zheng CZ Chen via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org"><u><font color="#0000FF">llvm-dev@lists.llvm.org</font></u></a>> wrote:
<ul><font size="2">Hi,</font><br><font size="2"><br>Very appreciate for all your input.</font><br><font size="2"><br>it is indeed a very aggressive optimization and it is not safe in many cases. But it should be helpful to tune application's performance if it is safe.</font><br><font size="2"><br>I think if we want to support it, we must:<br>1: only let compiler user turn it on by explicitly specifying -fforce-restrict-ptr-args, otherwise it is always off.<br>2: emit a warning message to remind this opt will change program semantics if users turn it on.<br>3: restrict its application to C/C++.</font><br><font size="2"><br>Any ideas?</font><br><font size="2"><br>Thanks.</font><br><font size="2"><br>BRS//<br>Chen Zheng<br>Power Compiler Backend Developer</font><br><br><br><img src="cid:1__=C7BB0916DFD062C88f9e8a93df938690918cC7B@" width="16" height="16" alt="Inactive hide details for Troy Johnson ---2019/01/16 02:32:22 AM---Restrict is supported by Clang for C++ via __restrict__, so"><font size="2" color="#424282">Troy Johnson ---2019/01/16 02:32:22 AM---Restrict is supported by Clang for C++ via __restrict__, so it seems strange to block using this pro</font><br><font size="2" color="#5F5F5F"><br>From: </font><font size="2">Troy Johnson <</font><a href="mailto:troyj@cray.com" target="_blank"><u><font size="2" color="#0000FF">troyj@cray.com</font></u></a><font size="2">></font><font size="2" color="#5F5F5F"><br>To: </font><font size="2">"Finkel, Hal J." <</font><a href="mailto:hfinkel@anl.gov" target="_blank"><u><font size="2" color="#0000FF">hfinkel@anl.gov</font></u></a><font size="2">>, Zheng CZ Chen <</font><a href="mailto:czhengsz@cn.ibm.com" target="_blank"><u><font size="2" color="#0000FF">czhengsz@cn.ibm.com</font></u></a><font size="2">></font><font size="2" color="#5F5F5F"><br>Cc: </font><font size="2">"</font><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="2" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><font size="2">" <</font><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="2" color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><font size="2">></font><font size="2" color="#5F5F5F"><br>Date: </font><font size="2">2019/01/16 02:32 AM</font><font size="2" color="#5F5F5F"><br>Subject: </font><font size="2">RE: [llvm-dev] Aggressive optimization opportunity</font><br><hr width="100%" size="2" align="left" noshade><br><br><font color="#1F497D"><br>Restrict is supported by Clang for C++ via __restrict__, so it seems strange to block using this proposed option for C++.</font><br><font color="#1F497D"><br>That said, this kind of option can be dangerous and should come with a suitable warning. We’ve had a similar option and in practice it’s been used to hunt for performance gains (i.e., turn it on and see what happens), but just because the code runs faster and produces the correct result with the option enabled doesn’t mean it is safe in all cases. And if it crashes or gives you wrong answers, you still don’t know which pointer had the alias that caused that problem. Either way, you still need to inspect all of the pointers and prove to yourself it is safe and at that point you might as well add restrict manually.</font><br><font color="#1F497D"><br>-Troy</font><br><b><br>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank"><u><font color="#0000FF">llvm-dev-bounces@lists.llvm.org</font></u></a>> <b>On Behalf Of </b>Finkel, Hal J. via llvm-dev<b><br>Sent:</b> Tuesday, January 15, 2019 9:57 AM<b><br>To:</b> Zheng CZ Chen <<a href="mailto:czhengsz@cn.ibm.com" target="_blank"><u><font color="#0000FF">czhengsz@cn.ibm.com</font></u></a>>; <a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><b><br>Subject:</b> Re: [llvm-dev] Aggressive optimization opportunity
<p><font face="Times New Roman"><br>On 1/15/19 6:07 AM, Zheng CZ Chen via llvm-dev wrote:</font><ul><ul><ul><ul><font size="2" face="Times New Roman">Hi,<br><br>There are some compilers with a aggressive optimization which restricts function pointer parameters. Let's say opt restrict_args. When restrict_args is turned on, compiler will treat all function pointer parameters as restrict one.</font></ul></ul></ul></ul><font face="Times New Roman">I certainly understand the use case, in a general sense. In my experience, these options are used with (fairly old) pre-C99 code bases (and specifically C, not C++), which follow something akin to a one-function-per-source-file model and which can't be modified (e.g., for licensing reasons). Using these options are certainly considered bad practice, and they only apply to certain legacy code bases. Does this match your experience and expected usage?</font><p><font face="Times New Roman">In an engineering sense, this seems like a trivial feature to support. I don't object to supporting it, but if we do, we probably want to:</font><p><font face="Times New Roman">1. Restrict it's application to C (e.g., it should be an error to use with C++, OpenCL, CUDA, and any other languages that Clang supports).</font><p><font face="Times New Roman">2. When used with C99 or later language standards, the use of this flag generates a warning on each function definition with a fixit hint showing where the restrict keyword should be placed (we can then, optionally of course, use these fixits to automatically upgrade code where possible using our corresponding infrastructure). This warning should have a separate flag, and is disabled by default for pre-C99 standard modes, and enabled by default otherwise, but can be toggled independently.</font><p><font face="Times New Roman">-Hal</font><ul><ul><ul><ul><i><font size="2" face="Times New Roman"><br>int foo(int * a) </font></i><font size="2" face="Times New Roman">+ restrict_args opt <br><br>equals to:</font><i><font size="2" face="Times New Roman"><br><br>int foo(int * restrict a)</font></i><font face="Times New Roman"><br></font><font size="2" face="Times New Roman"><br><br>Here is a complete example:<br>source code:<br>extern int num;</font><i><font size="2" face="Times New Roman"><br>int foo(int * a)<br>{<br>(*a) = 10;<br>num++;<br>(*a)++;<br><br>return *a; <br>}</font></i><font size="2" face="Times New Roman"><br><br>Using IBM xlc compiler with option -qrestrict at -O2, we get result:<br><br>0000000000000000 <foo>:<br>0: 00 00 4c 3c addis r2,r12,0<br>4: 00 00 42 38 addi r2,r2,0<br>8: 00 00 a2 3c addis r5,r2,0<br>c: 00 00 a5 e8 ld r5,0(r5)<br>10: 0b 00 00 38 li r0,11<br>14: 00 00 03 90 stw r0,0(r3)<br>18: 00 00 85 80 lwz r4,0(r5)</font><b><font size="2" face="Times New Roman"><br>1c: 0b 00 60 38 li r3,11 ------>since we confirm num will not change the content where pointer to, compiler can directly return 11.</font></b><font size="2" face="Times New Roman"><br>20: 01 00 04 38 addi r0,r4,1<br>24: 00 00 05 90 stw r0,0(r5)<br>28: 20 00 80 4e blr<br><br>Seems clang does not have such optimization. And I don't find similar option in gcc either.<br><br>Is it possible to add this optimization into clang?<br><br>Thanks.<br><br>BRS//<br>Chen Zheng<br>Power Compiler Backend Developer</font><font face="Times New Roman"><br></font><br><font size="2" face="Courier New"><br>_______________________________________________<br>LLVM Developers mailing list</font><u><font color="#0000FF"><br></font></u><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font size="2" color="#0000FF" face="Courier New">llvm-dev@lists.llvm.org</font></u></a><u><font color="#0000FF"><br></font></u><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank"><u><font size="2" color="#0000FF" face="Courier New">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</font></u></a></ul></ul></ul></ul><font size="2" face="Courier New">-- <br>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory</font><br><br><br>_______________________________________________<br>LLVM Developers mailing list<u><font color="#0000FF"><br></font></u><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><u><font color="#0000FF">llvm-dev@lists.llvm.org</font></u></a><u><font color="#0000FF"><br></font></u><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank"><u><font color="#0000FF">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</font></u></a><br><br></ul><BR>
</body></html>