<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; "><div style="font-family: 'times new roman', 'new york', times, serif; "><div id="yiv1913375219"><div style="background-color: rgb(255, 255, 255); font-family: 'times new roman', 'new york', times, serif; "><div style="font-family: times, serif; "><div style="font-family: times, serif; ">
<div id="yiv1913375219"><div style="background-color: rgb(255, 255, 255); font-family: times, serif; "><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; "><br></div><div style="font-family: times, serif; "><div style="font-family: times, serif; ">
<div id="yiv1913375219"><div style="background-color: rgb(255, 255, 255); font-family: times, serif; "><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; ">Hello .</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; "><div class="yiv1913375219yui_3_2_0_20_134301829836475"><br></div></div><div class="yiv1913375219yui_3_2_0_20_134301829836475" style="font-size: 12pt; font-family: times, serif; color: rgb(0, 0, 0); ">I ran opt with -indvars options , got wrong result. </div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">This is my example:</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">test.cc : </div><div style="color: rgb(0, 0, 0); font-family: times, serif;
 font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><span class="Apple-tab-span" style="white-space:pre">            </span>int test(int a)</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">                {</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><span class="Apple-tab-span" style="white-space:pre">            </span>     for (int i = 2; i < a; ++i) {</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">                           a += ;</div><div
 style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><span class="Apple-tab-span" style="white-space:pre">                </span>     }</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><span class="Apple-tab-span" style="white-space:pre">   </span>             return a;</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><span class="Apple-tab-span" style="white-space:pre">               </span>}</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">clang -O3 -emit-llvm -S test.cc -o test.ll</div><div
 style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">opt -indvards -S test.ll  -o indvars.ll > /dev/null</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">indvars.ll :</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">; ModuleID = 'test.ll'</div><div
 class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">target triple = "i386-pc-linux-gnu"</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">define i32 @_Z4testi(i32 %a) nounwind readnone {</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">entry:</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %cmp1 = icmp sgt i32 %a, 2</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  br i1 %cmp1, label %for.body.preheader, label
 %for.end</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">for.body.preheader:                               ; preds = %entry</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  br label %for.body</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">for.body:                                         ; preds = %for.body.preheader, %for.body</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %a.addr.03 = phi i32 [ %add, %for.body ], [ %a,
 %for.body.preheader ]  <span style="font-weight: bold;">//should start at 0 , I think there is no Canonicalize Induction Variable</span></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %i.02 = phi i32 [ %inc, %for.body ], [ 2, %for.body.preheader ]</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %add = add nsw i32 %a.addr.03, %i.02</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %inc = add nsw i32 %i.02, 1</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %cmp = icmp slt i32 %inc, %add</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  br i1 %cmp, label %for.body, label %for.end.loopexit</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div
 class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">for.end.loopexit:                                 ; preds = %for.body</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %add.lcssa = phi i32 [ %add, %for.body ]</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  br label %for.end</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199"><br></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">for.end:                                          ; preds = %for.end.loopexit, %entry</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  %a.addr.0.lcssa =
 phi i32 [ %a, %entry ], [ %add.lcssa, %for.end.loopexit ]</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">  ret i32 %a.addr.0.lcssa</div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yui_3_2_0_19_134316941189199">}</div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; "><br></div></div><div class="yiv1913375219yui_3_2_0_20_134301829836475 yiv1913375219yui_3_2_0_19_134308788264589" style="font-family: times, serif; "><span style="font-size: 12pt;">Someone can </span>explain <span style="font-size: 12pt;">why?</span></div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; " class="yiv1913375219yui_3_2_0_20_134301829836475 yiv1913375219yui_3_2_0_19_134308788264589 yui_3_2_0_19_1343169411891101"><br></div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; "><span><font face="times new roman, new york, times, serif"
 size="3">Thanks in advance,</font></span></div><div style="color: rgb(0, 0, 0); font-family: times, serif; font-size: 12pt; "><span><font face="times new roman, new york, times, serif" size="3">Edvard </font></span></div></div></div><br><br> </div> </div>  </div></div><br><br> </div> </div>  </div></div><br><br> </div> </div>  </div></body></html>