[PATCH] Divergence analysis for GPU programs

Jingyue Wu jingyue at google.com
Wed Apr 8 21:35:57 PDT 2015


Thanks for your review, Diogo! As you suggested, the new patch (
http://reviews.llvm.org/D8576) now considers laneid.

Jingyue

On Wed, Apr 8, 2015 at 3:31 PM Diogo Sampaio <dnsampaio at gmail.com> wrote:

> Hi Jingyue,
>
> Very nice code and good comments. It's nice to see this analysis in
> llvm and I believe your code is correct. There is one slight point,
> not very common, which I faced. The use the intrinsic laneId, most of
> the times generated by nvcc, also leads to divergence. I would change
> the file NVPTXTargetTransformInfo.cpp either by adding
> Intrinsic::int_ptx_read_laneid to the switch in "static bool
> readsThreadIndex(const IntrinsicInst *II)" or just creating a method
> for it such as...
>
> static bool readsLaneId(const IntrinsicInst *II) {
>   return (II->getIntrinsicID() == Intrinsic::int_ptx_read_laneid);
> }
> ..... and changing the test to ...
>     if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
>       // Instructions that read threadIdx or laneId are obviously
> divergent.
>       if (readsThreadIndex(II) || readsLaneId(II))
>         return true;
> .
>
> Now, more as an discussion:
> In the file DivergenceAnalysis.cpp, line 206
> if (!cast<PHINode>(I)->hasConstantValue() && DV.insert(I).second)
>       Worklist.push_back(I);
>
> I was wondering about the effectiveness of the method
> PhiNode::hasConstantValue.
> For example, in a code such as:
> //not a smart code, I know
> if(divergentBool){
> a0 = b1 - c1;
> }else{
> c2 = -c1;
> a1 = b1 + c2;
> }
> a2 = phi(a0, a1);
>
>
Given the code as is, DivergenceAnalysis will consider a2 divergent.

However, I wouldn't worry about it. We plan to run this analysis pass at a
relatively late stage (definitely after InstCombine), so the code pattern
you listed here is likely optimized away. In fact, even a PHINode with same
incoming values is probably optimized away.


> Will this method be good enough to say that a2 is not divergent? I
> believe that llvm's ScalarEvolution could detect they are the same
> value.
>
> And to end, there are 2 typos in your header file:
> exeuction
> pogram
>
>
> Very nice work,
> regards
> --
> Diogo Nunes Sampaio
>
> Portable: +33 6 59 05 75 57
>
> INRIA - Institut national de recherche en informatique et en automatique
> CORSE - http://www.inria.fr/equipes/corse
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150409/896786a4/attachment.html>


More information about the llvm-commits mailing list