<div dir="ltr">This seems fine to me, but I'd like to make sure it looks OK to Nick as well.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 17, 2014 at 12:37 AM, Jingyue Wu <span dir="ltr"><<a href="mailto:jingyue@google.com" target="_blank">jingyue@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>Hi, </div><div><br></div><div>The range metadata can only be attached to LoadInst for now. I am considering extending its usage to IntrinsicInst so that the frontend can annotate the range of the return value of an intrinsic call. e.g.,</div>

<div>%a = call i32 @llvm.xxx(), !range !0</div><div>!0 = metadata !{ i32 0, i23 1024 }</div>

<div><br></div><div>The motivation behind this extension is some optimizations we are working on for CUDA programs. Some special registers in CUDA (e.g., threadIdx.x) are bounded per CUDA programming guide, and knowing their ranges can improve the precision of ValueTracking and benefit optimizations such as InstCombine. </div>


<div><br></div><div>To implement this idea, we need ValueTracking to be aware of the ranges of these special variables. These special registers are so far read-only and accessed using intrinsics. e.g., </div>
<div>%threadIdx.x = call i32 @llvm.nvvm.read.ptx.sreg.tid.x().</div><div><br></div><div>One possible approach is to have ValueTracking compute the known bits of these intrinsics as special cases. This approach is already taken for the x86_sse42_crc32_64_64 intrinsic. However, this approach may not be elegant because the ranges of these CUDA special registers depend on the GPU compute capability specified by -target-cpu. For instance, blockIdx.x is bounded by 65535 in sm_20 but 2^31-1 in sm_30. Exposing -target-cpu to ValueTracking is probably discouraged. </div>


<div><br></div><div>Therefore, the approach I am considering is to have clang annotate the ranges of these CUDA special registers according to the -target-cpu flag, and have ValueTracking pick the range metadata for optimization. By doing so, we hide the target-specific info from ValueTracking. </div>


<div><br></div><div>The code change in llvm minus clang won't be large. The core change is only a few lines: <a href="http://reviews.llvm.org/differential/diff/10464/" target="_blank">http://reviews.llvm.org/differential/diff/10464/</a>. If this extension sounds good to you, I'll definitely add more tests and revise the documents on range metadata. </div>

<div><br></div><div>Best,</div><div>Jingyue</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>