<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 17 June 2014 06:41, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@google.com" target="_blank">eliben@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 Tue, Jun 17, 2014 at 1:38 AM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div>Chandler Carruth wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This seems fine to me, but I'd like to make sure it looks OK to Nick as<br>
well.<br>
</blockquote>
<br></div>
I strongly prefer baking in knowledge about the intrinsics themselves into the passes if possible. Metadata will always be secondary.<br></blockquote><div><br></div></div><div>So you're saying that in this particular case you'd prefer LLVM passes to know about the range of these PTX intrinsics, rather than Clang adding them as metadata?</div>

</div></div></div></blockquote><div><br></div><div>Yep.</div><div><br></div><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>ValueTracking.cpp already has some iffy target knowledge (someone sneaked a direct  Intrinsic::x86_sse42_crc32_64_64 check in there), but extending it to other intrinsics in other targets seems like too much...</div>

</div></div></div></blockquote><div><br></div><div>That's not iffy. That's exactly how it should work, and we should have more of that. There is a major gotcha and that's dealing with the case where the intrinsics don't exist because the backend wasn't compiled in. If x86_sse42_crc32_64_64 is in there (and also in instcombine btw), presumably that problem is solved somehow? Or does llvm actually not build if you don't enable the x86 target? I feel like we would've heard about that.</div>

<div><br></div><div>Nick</div><div><br></div><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> So should target info be passed into it in some way? Any suggestions where to put it? TargetLibraryInfo? TargetTransformInfo? In any case this seems like the target interface will have to be augmented, and we'll have to carry an object around into ValueTracking's compute* functions. If this is the right way, then this is the way it will be done - design ideas are appreciated.<br>

</div></div><span class="HOEnZb"><font color="#888888">

<div class="gmail_quote"><br></div><div class="gmail_quote">Eli</div></font></span><div><div class="h5"><div class="gmail_quote"><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<br>
Separately, should value tracking look use range metadata when it's available? Absolutely.<br>
<br>
I think it should apply to all CallInst not just IntrinsicInst (which is derived from CallInst).<br>
<br>
Nick<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
On Tue, Jun 17, 2014 at 12:37 AM, Jingyue Wu <<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a><br></div><div><div>
<mailto:<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    The range metadata can only be attached to LoadInst for now. I am<br>
    considering extending its usage to IntrinsicInst so that the<br>
    frontend can annotate the range of the return value of an intrinsic<br>
    call. e.g.,<br>
    %a = call i32 @llvm.xxx(), !range !0<br>
    !0 = metadata !{ i32 0, i23 1024 }<br>
<br>
    The motivation behind this extension is some optimizations we are<br>
    working on for CUDA programs. Some special registers in CUDA (e.g.,<br>
    threadIdx.x) are bounded per CUDA programming guide, and knowing<br>
    their ranges can improve the precision of ValueTracking and benefit<br>
    optimizations such as InstCombine.<br>
<br>
    To implement this idea, we need ValueTracking to be aware of the<br>
    ranges of these special variables. These special registers are so<br>
    far read-only and accessed using intrinsics. e.g.,<br>
    %threadIdx.x = call i32 @llvm.nvvm.read.ptx.sreg.tid.<u></u>x().<br>
<br>
    One possible approach is to have ValueTracking compute the known<br>
    bits of these intrinsics as special cases. This approach is already<br>
    taken for the x86_sse42_crc32_64_64 intrinsic. However, this<br>
    approach may not be elegant because the ranges of these CUDA special<br>
    registers depend on the GPU compute capability specified by<br>
    -target-cpu. For instance, blockIdx.x is bounded by 65535 in sm_20<br>
    but 2^31-1 in sm_30. Exposing -target-cpu to ValueTracking is<br>
    probably discouraged.<br>
<br>
    Therefore, the approach I am considering is to have clang annotate<br>
    the ranges of these CUDA special registers according to the<br>
    -target-cpu flag, and have ValueTracking pick the range metadata for<br>
    optimization. By doing so, we hide the target-specific info from<br>
    ValueTracking.<br>
<br>
    The code change in llvm minus clang won't be large. The core change<br>
    is only a few lines:<br>
    <a href="http://reviews.llvm.org/differential/diff/10464/" target="_blank">http://reviews.llvm.org/<u></u>differential/diff/10464/</a>. If this extension<br>
    sounds good to you, I'll definitely add more tests and revise the<br>
    documents on range metadata.<br>
<br>
    Best,<br>
    Jingyue<br>
<br>
    ______________________________<u></u>_________________<br>
    LLVM Developers mailing list<br></div></div>
    <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><div>



<br>
    <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</div></blockquote><div><div>
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>