<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Dear Dong,<br>
      <br>
      First, how did you generate the LLVM IR?  Did you run any
      optimizations on the code?<br>
      <br>
      Second, what is it that you are trying to do, and is having more
      than one induction variable a problem?  I would think that, in
      general, a loop can have multiple induction variables, so you will
      probably need to handle that issue no matter what you are doing.<br>
      <br>
      Third, to see what generates this code, you should first use clang
      -S -emit-llvm to generate an LLVM assembly file.  Look at the
      assembly file and see if it has the two induction variables.  If
      it does, then it's clang that is generating the code that way.  If
      it doesn't, then some optimization is responsible.<br>
      <br>
      If it's an optimization, you can narrow it down as follows: write
      a pass that crashes (e.g., use an assert() statement) if it
      detects a loop with two induction variables.  Then, use bugpoint
      to run your pass.  The bugpoint program will reduce the crash to
      the minimum number of passes and minimum code that triggers the
      crash.  In this case, that would be equivalent to finding the pass
      that generates the second induction variable.<br>
      <br>
      Fourth, in the future, please attach plain text files instead of
      image files.  I can download a plain text file, search through it,
      assemble it with the LLVM assembler, etc.  Image files do not
      allow for that.  Also, images tend to take more space than simple
      text files.<br>
      <br>
      Regards,<br>
      <br>
      John Criswell<br>
      <br>
      <br>
      On 7/13/16 1:19 PM, Dong Chen via llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CAFHTND77pNPMOS3rX6r7AwQpJ9R52fsUQfsf-LNqbstTuJ9ATw@mail.gmail.com"
      type="cite">
      <div dir="ltr">The C source code:
        <div><br>
        </div>
        <div>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">__kernel void adi_kernel</span><span
              style="color:rgb(195,55,32)">1</span><span
              style="color:rgb(213,59,211)">(</span><span style="">__global
              DATA_TYPE* A, __global DATA_TYPE* B, __global DATA_TYPE*
              X, int n</span><span style="color:rgb(213,59,211)">)</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">{</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  int i</span><span style="color:rgb(195,55,32)">1</span><span
              style=""> </span><span style="color:rgb(206,121,36)">=</span><span
              style=""> get_global_id</span><span
              style="color:rgb(213,59,211)">(</span><span
              style="color:rgb(195,55,32)">0</span><span
              style="color:rgb(213,59,211)">)</span><span
              style="color:rgb(83,48,225)">;</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  int i</span><span style="color:rgb(195,55,32)">2</span><span
              style="color:rgb(83,48,225)">; </span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0);min-height:14px"><span
              style=""></span><br>
          </p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  </span><span style="color:rgb(206,121,36)">if</span><span
              style=""> </span><span style="color:rgb(213,59,211)">((</span><span
              style="">i1 </span><span style="color:rgb(206,121,36)"><</span><span
              style=""> n</span><span style="color:rgb(213,59,211)">))</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  {</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(83,48,225);background-color:rgb(0,0,0)"><span
              style="color:rgb(77,186,43)">    for </span><span
              style="color:rgb(213,59,211)">(</span><span
              style="color:rgb(77,186,43)">i2 </span><span
              style="color:rgb(206,121,36)">=</span><span
              style="color:rgb(77,186,43)"> </span><span
              style="color:rgb(195,55,32)">1</span><span style="">; i2
              < n; i2++)</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">    {</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">      X[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">=</span><span
              style=""> X[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">-</span><span
              style=""> X[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> </span><span
              style="color:rgb(213,59,211)">(</span><span style="">i2-1</span><span
              style="color:rgb(213,59,211)">)</span><span style="">] </span><span
              style="color:rgb(206,121,36)">*</span><span style="">
              A[i1*n </span><span style="color:rgb(206,121,36)">+</span><span
              style=""> i2] </span><span style="color:rgb(206,121,36)">/</span><span
              style=""> B[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> </span><span
              style="color:rgb(213,59,211)">(</span><span style="">i2-1</span><span
              style="color:rgb(213,59,211)">)</span><span style="">]</span><span
              style="color:rgb(83,48,225)">;</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">      B[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">=</span><span
              style=""> B[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">-</span><span
              style=""> A[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">*</span><span
              style=""> A[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> i2]
            </span><span style="color:rgb(206,121,36)">/</span><span
              style=""> B[i1*n </span><span
              style="color:rgb(206,121,36)">+</span><span style=""> </span><span
              style="color:rgb(213,59,211)">(</span><span style="">i2-1</span><span
              style="color:rgb(213,59,211)">)</span><span style="">]</span><span
              style="color:rgb(83,48,225)">;</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">    }</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  }</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">}</span></p>
        </div>
        <div><br>
        </div>
        <div>Only one induction variable (i2) in the source. But in the
          IR i2.087 and indvars.iv are all induction variables (I
          think). Any body know why this happens? Is there a way to
          generate only one induction variables?</div>
        <div><br>
        </div>
        <div>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">; Function Attrs: nounwind ssp uwtable</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">define void @adi_kernel1(float* nocapture
              readonly %A, float* nocapture %B, float* nocapture %X, i32
              %n) #0 {</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">entry:</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %call = tail call i32 (i32, ...) bitcast (i32
              (...)* @get_global_id to i32 (i32, ...)*)(i32 0) #2</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %cmp = icmp slt i32 %call, %n</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %cmp186 = icmp sgt i32 %n, 1</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %or.cond = and i1 %cmp, %cmp186</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  br i1 %or.cond, label %<a
                moz-do-not-send="true" href="http://for.body.lr.ph">for.body.lr.ph</a>,
              label %if.end</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0);min-height:14px"><span
              style=""></span><br>
          </p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style=""><a moz-do-not-send="true"
                href="http://for.body.lr.ph">for.body.lr.ph</a>:        
                                        ; preds = %entry</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %mul = mul nsw i32 %call, %n</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %sub = add i32 %mul, -1</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  br label %for.body</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0);min-height:14px"><span
              style=""></span><br>
          </p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">for.body:                                        
              ; preds = %for.body, %<a moz-do-not-send="true"
                href="http://for.body.lr.ph">for.body.lr.ph</a></span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %indvars.iv = phi i64 [ 1, %<a
                moz-do-not-send="true" href="http://for.body.lr.ph">for.body.lr.ph</a>
              ], [ %indvars.iv.next, %for.body ]</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %i2.087 = phi i32 [ 1, %<a
                moz-do-not-send="true" href="http://for.body.lr.ph">for.body.lr.ph</a>
              ], [ %inc, %for.body ]</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %add = add nsw i32 %i2.087, %mul</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %idxprom = sext i32 %add to i64</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %arrayidx = getelementptr inbounds float,
              float* %X, i64 %idxprom</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %0 = load float, float* %arrayidx, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %1 = trunc i64 %indvars.iv to i32</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %add3 = add i32 %sub, %1</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %idxprom4 = sext i32 %add3 to i64</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %arrayidx5 = getelementptr inbounds float,
              float* %X, i64 %idxprom4</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %2 = load float, float* %arrayidx5, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %arrayidx9 = getelementptr inbounds float,
              float* %A, i64 %idxprom</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %3 = load float, float* %arrayidx9, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %mul10 = fmul float %2, %3</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %arrayidx15 = getelementptr inbounds float,
              float* %B, i64 %idxprom4</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %4 = load float, float* %arrayidx15, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %div = fdiv float %mul10, %4, !fpmath !12</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %sub16 = fsub float %0, %div</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  store float %sub16, float* %arrayidx, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %arrayidx24 = getelementptr inbounds float,
              float* %B, i64 %idxprom</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %5 = load float, float* %arrayidx24, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %6 = load float, float* %arrayidx9, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %mul33 = fmul float %6, %6</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %7 = load float, float* %arrayidx15, align 4,
              !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %div39 = fdiv float %mul33, %7, !fpmath !12</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %sub40 = fsub float %5, %div39</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  store float %sub40, float* %arrayidx24, align
              4, !tbaa !8</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %indvars.iv.next = add nuw nsw i64 %indvars.iv,
              1</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %inc = add nuw nsw i32 %i2.087, 1</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %lftr.wideiv = trunc i64 %indvars.iv.next to
              i32</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  %exitcond = icmp eq i32 %lftr.wideiv, %n</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  br i1 %exitcond, label %if.end.loopexit, label
              %for.body</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0);min-height:14px"><span
              style=""></span><br>
          </p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">if.end.loopexit:                                 
              ; preds = %for.body</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  br label %if.end</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0);min-height:14px"><span
              style=""></span><br>
          </p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">if.end:                                          
              ; preds = %if.end.loopexit, %entry</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">  ret void</span></p>
          <p
style="margin:0px;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(77,186,43);background-color:rgb(0,0,0)"><span
              style="">}</span></p>
        </div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div><br>
        </div>
        <div>Dong</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>