<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, Apr 13, 2018 at 9:12 AM James Y Knight <<a href="mailto:jyknight@google.com">jyknight@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I actually was working on an updated patch for the LLVM-side of this, also. :) I was just working on some test cases; I'll post it soon. It's somewhat different than yours.<div><br></div></div></blockquote><div>Oh cool! I'll look at the Phab entry. :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I haven't touched the clang side yet, but I think it needs to be more complex than what you have there. I think it actually needs to be able to evaluate the intrinsic as a constant _false_ in the front-end in some circumstances, rather than always emitting IR if it cannot tell the answer is true.</div></div><br></blockquote><div>It would only be "false" if the function cannot be inlined, right? Otherwise you don't really know. So at -O0, we can safely mark something as "false". But in other cases, we would need to be wary. </div><div><br></div><div>-bw</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr">On Thu, Apr 12, 2018 at 5:10 PM Bill Wendling via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello again!<div><br></div><div>I took a stab at PR4898[1]. The attached patch improves Clang's <font face="monospace">__builtin_constant_p</font> support so that the Linux kernel is happy. With this improvement, Clang can determine if <font face="monospace">__builtin_constant_p</font> is true or false after inlining.</div><div><br></div><div>As an example:</div><div><br></div><div><div><font face="monospace">static __attribute__((always_inline)) int foo(int x) {</font></div><div><font face="monospace"><span style="white-space:pre-wrap">     </span>if (__builtin_constant_p(x))</font></div><div><font face="monospace"><span style="white-space:pre-wrap">         </span>return 1;</font></div><div><font face="monospace"><span style="white-space:pre-wrap">    </span>return 0;</font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">static __attribute__((always_inline)) int mux() {</font></div><div><font face="monospace"><span style="white-space:pre-wrap">       </span>if (__builtin_constant_p(37))</font></div><div><font face="monospace"><span style="white-space:pre-wrap">                </span>return 927;</font></div><div><font face="monospace"><span style="white-space:pre-wrap">  </span>return 0;</font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">int bar(int a) {</font></div><div><font face="monospace"><span style="white-space:pre-wrap">        </span>if (a)</font></div><div><font face="monospace"><span style="white-space:pre-wrap">               </span>return foo(42);</font></div><div><font face="monospace"><span style="white-space:pre-wrap">      </span>else</font></div><div><font face="monospace"><span style="white-space:pre-wrap">         </span>return mux();</font></div><div><font face="monospace">}</font></div></div><div><br></div><div>Now outputs this code at -O1:</div><div><br></div><div><font face="monospace">bar:</font></div><div><div><font face="monospace"><span style="white-space:pre-wrap">        </span>.cfi_startproc</font></div><div><font face="monospace"># %bb.0:                                # %entry</font></div><div><font face="monospace"><span style="white-space:pre-wrap">    </span>testl<span style="white-space:pre-wrap">   </span>%edi, %edi</font></div><div><font face="monospace"><span style="white-space:pre-wrap">   </span>movl<span style="white-space:pre-wrap">    </span>$927, %ecx              # imm = 0x39F</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap">    </span>$1, %eax</font></div><div><font face="monospace"><span style="white-space:pre-wrap">     </span>cmovel<span style="white-space:pre-wrap">  </span>%ecx, %eax</font></div><div><font face="monospace"><span style="white-space:pre-wrap">   </span>retq</font></div></div><div><br></div><div>And this code at -O0:</div><div><br></div><div><div><font face="monospace">bar:                                    # @bar</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>.cfi_startproc</font></div><div><font face="monospace"># %bb.0:                                # %entry</font></div><div><font face="monospace"><span style="white-space:pre-wrap">    </span>pushq<span style="white-space:pre-wrap">   </span>%rbp</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>.cfi_def_cfa_offset 16</font></div><div><font face="monospace"><span style="white-space:pre-wrap">       </span>.cfi_offset %rbp, -16</font></div><div><font face="monospace"><span style="white-space:pre-wrap">        </span>movq<span style="white-space:pre-wrap">    </span>%rsp, %rbp</font></div><div><font face="monospace"><span style="white-space:pre-wrap">   </span>.cfi_def_cfa_register %rbp</font></div><div><font face="monospace"><span style="white-space:pre-wrap">   </span>movl<span style="white-space:pre-wrap">    </span>%edi, -16(%rbp)</font></div><div><font face="monospace"><span style="white-space:pre-wrap">      </span>cmpl<span style="white-space:pre-wrap">    </span>$0, -16(%rbp)</font></div><div><font face="monospace"><span style="white-space:pre-wrap">        </span>je<span style="white-space:pre-wrap">      </span>.LBB0_2</font></div><div><font face="monospace"># %bb.1:                                # %if.then</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap">    </span>$42, -8(%rbp)</font></div><div><font face="monospace"><span style="white-space:pre-wrap">        </span>movl<span style="white-space:pre-wrap">    </span>$0, -4(%rbp)</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap">    </span>-4(%rbp), %eax</font></div><div><font face="monospace"><span style="white-space:pre-wrap">       </span>movl<span style="white-space:pre-wrap">    </span>%eax, -12(%rbp)</font></div><div><font face="monospace"><span style="white-space:pre-wrap">      </span>jmp<span style="white-space:pre-wrap">     </span>.LBB0_3</font></div><div><font face="monospace">.LBB0_2:                                # %if.else</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap">    </span>$927, -12(%rbp)         # imm = 0x39F</font></div><div><font face="monospace">.LBB0_3:                                # %return</font></div><div><font face="monospace"><span style="white-space:pre-wrap">       </span>movl<span style="white-space:pre-wrap">    </span>-12(%rbp), %eax</font></div><div><font face="monospace"><span style="white-space:pre-wrap">      </span>popq<span style="white-space:pre-wrap">    </span>%rbp</font></div><div><font face="monospace"><span style="white-space:pre-wrap"> </span>retq</font></div></div><div><br></div><div>If the patch looks okay to people, I can shove it onto Phabricator for a review. (My phab-fu is bad.)</div><div><br></div><div>Thoughts?</div><div><br></div><div>-bw</div><div><br></div><div>[1] <a href="https://bugs.llvm.org/show_bug.cgi?id=4898" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=4898</a></div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></blockquote></div></div>