<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi all,<div class=""><br class=""></div><div class="">For the following code </div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">int</span> countHundred( <span style="color: #ba2da2" class="">int</span> num )</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">int</span> count = <span style="color: #272ad8" class="">0</span>;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">while</span> ( num >= <span style="color: #272ad8" class="">100</span>) { count++ ; num = num - <span style="color: #272ad8" class="">100</span>; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">return</span> count;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">}</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">the loop shown above is optimised away and replaced by ‘udiv’ instruction like this</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">define i16 @countHundred(i16 %num) {</div><div style="margin: 0px; line-height: normal;" class="">entry:</div><div style="margin: 0px; line-height: normal;" class=""> %cmp3 = icmp sgt i16 %num, 99</div><div style="margin: 0px; line-height: normal;" class=""> br i1 %cmp3, label %while.body.preheader, label %while.end</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">while.body.preheader: ; preds = %entry</div><div style="margin: 0px; line-height: normal;" class=""> %0 = add nsw i16 %num, -100</div><div style="margin: 0px; line-height: normal;" class=""> %1 = udiv i16 %0, 100</div><div style="margin: 0px; line-height: normal;" class=""> %2 = add nuw nsw i16 %1, 1</div><div style="margin: 0px; line-height: normal;" class=""> br label %while.end</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">while.end: ; preds = %while.body.preheader, %entry</div><div style="margin: 0px; line-height: normal;" class=""> %count.0.lcssa = phi i16 [ 0, %entry ], [ %2, %while.body.preheader ]</div><div style="margin: 0px; line-height: normal;" class=""> ret i16 %count.0.lcssa</div><div style="margin: 0px; line-height: normal;" class="">}</div></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">The above was compiled for the MSP430 target with the -Os flag but similar results are obtained with the other options except -O0</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Any pointers about where does that transform happen would be appreciated (I posted a similar question in cfe-dev).</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Thanks in advance</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">John.</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div></div></body></html>