[LLVMdev] Attaching range metadata to IntrinsicInst

Philip Reames listmail at philipreames.com
Tue Jun 17 10:20:48 PDT 2014


On 06/17/2014 01:38 AM, Nick Lewycky wrote:
> Chandler Carruth wrote:
>> This seems fine to me, but I'd like to make sure it looks OK to Nick as
>> well.
>
> I strongly prefer baking in knowledge about the intrinsics themselves 
> into the passes if possible. Metadata will always be secondary.
This dual approach seems non-ideal.  I'll agree it's workable, but are 
there other options?  I can see a couple of possible ones:
- Adding an attribute for range on return or parameter values.  This 
removes the dropped metadata problem.
- Extending the function attribute inference pass to add range metadata 
for known functions/intrinsics.  This would ensure that the range 
metadata could get reintroduced if some pass dropped it.  This seems 
messy though.
- Introduce a mechanism to canonicalize metadata and attributes on 
target intrinsics.  The target provides a function which updates the 
intrinsic declaration (and call site?) as desired.  The optimization 
passes call this on every target intrinsic before anything else, then 
proceed to use the metadata for optimization.

I don't really like any of these; I'm mostly throwing them out in case 
it sparks an idea for someone.



>
> Separately, should value tracking look use range metadata when it's 
> available? Absolutely.
Agreed.
>
> I think it should apply to all CallInst not just IntrinsicInst (which 
> is derived from CallInst).
Yes please.  It should also apply to InvokeInst as well.
>
> Nick
>
>> On Tue, Jun 17, 2014 at 12:37 AM, Jingyue Wu <jingyue at google.com
>> <mailto:jingyue at google.com>> wrote:
>>
>>     Hi,
>>
>>     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.,
>>     %a = call i32 @llvm.xxx(), !range !0
>>     !0 = metadata !{ i32 0, i23 1024 }
>>
>>     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.
>>
>>     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.,
>>     %threadIdx.x = call i32 @llvm.nvvm.read.ptx.sreg.tid.x().
>>
>>     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.
>>
>>     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.
>>
>>     The code change in llvm minus clang won't be large. The core change
>>     is only a few lines:
>>     http://reviews.llvm.org/differential/diff/10464/. If this extension
>>     sounds good to you, I'll definitely add more tests and revise the
>>     documents on range metadata.
>>
>>     Best,
>>     Jingyue
>>
>>     _______________________________________________
>>     LLVM Developers mailing list
>>     LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> 
>> http://llvm.cs.uiuc.edu
>>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list