<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div>On Jul 11, 2013, at 12:29 AM, Michele Scandale <<a href="mailto:michele.scandale@gmail.com">michele.scandale@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"> Here an updated version of the patch fixing code style as suggested by Andrew.<br></div></blockquote><div dir="auto"><br></div>Committed r186107. Thanks.</div><div dir="auto">-Andy</div><div dir="auto"><br><div dir="auto"></div><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br> Thanks again.<br><br> Michele Scandale<br><br>Hi atrick,<br><br><a href="http://llvm-reviews.chandlerc.com/D1112">http://llvm-reviews.chandlerc.com/D1112</a><br><br>CHANGE SINCE LAST DIFF<br> <a href="http://llvm-reviews.chandlerc.com/D1112?vs=2713&id=2765#toc">http://llvm-reviews.chandlerc.com/D1112?vs=2713&id=2765#toc</a><br><br>Files:<br> lib/Transforms/Scalar/IndVarSimplify.cpp<br> test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll<br><br>Index: lib/Transforms/Scalar/IndVarSimplify.cpp<br>===================================================================<br>--- lib/Transforms/Scalar/IndVarSimplify.cpp<br>+++ lib/Transforms/Scalar/IndVarSimplify.cpp<br>@@ -1612,10 +1612,29 @@<br>               << "  IVCount:\t" << *IVCount << "\n");<br><br>  IRBuilder<> Builder(BI);<br>-  if (SE->getTypeSizeInBits(CmpIndVar->getType())<br>-      > SE->getTypeSizeInBits(ExitCnt->getType())) {<br>-    CmpIndVar = Builder.CreateTrunc(CmpIndVar, ExitCnt->getType(),<br>-                                    "lftr.wideiv");<br>+<br>+  unsigned CmpIndVarSize = SE->getTypeSizeInBits(CmpIndVar->getType());<br>+  unsigned ExitCntSize = SE->getTypeSizeInBits(ExitCnt->getType());<br>+  if (CmpIndVarSize > ExitCntSize) {<br>+    const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));<br>+    const SCEV *ARStart = AR->getStart();<br>+    const SCEV *ARStep = AR->getStepRecurrence(*SE);<br>+    if (isa<SCEVConstant>(ARStart) && isa<SCEVConstant>(IVCount)) {<br>+      const APInt &Start = cast<SCEVConstant>(ARStart)->getValue()->getValue();<br>+      const APInt &Count = cast<SCEVConstant>(IVCount)->getValue()->getValue();<br>+<br>+      APInt NewLimit;<br>+      if (cast<SCEVConstant>(ARStep)->getValue()->isNegative())<br>+        NewLimit = Start - Count.zext(CmpIndVarSize);<br>+      else<br>+        NewLimit = Start + Count.zext(CmpIndVarSize);<br>+      ExitCnt = ConstantInt::get(CmpIndVar->getType(), NewLimit);<br>+<br>+      DEBUG(dbgs() << "  Widen RHS:\t" << *ExitCnt << "\n");<br>+    } else {<br>+      CmpIndVar = Builder.CreateTrunc(CmpIndVar, ExitCnt->getType(),<br>+                                      "lftr.wideiv");<br>+    }<br>  }<br><br>  Value *Cond = Builder.CreateICmp(P, CmpIndVar, ExitCnt, "exitcond");<br>Index: test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll<br>===================================================================<br>--- test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll<br>+++ test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll<br>@@ -0,0 +1,25 @@<br>+;RUN: opt -S %s -indvars | FileCheck %s<br>+<br>+; Function Attrs: nounwind uwtable<br>+define void @foo() #0 {<br>+entry:<br>+  br label %for.body<br>+<br>+for.body:                                         ; preds = %entry, %for.body<br>+  %i.01 = phi i16 [ 0, %entry ], [ %inc, %for.body ]<br>+  %conv2 = sext i16 %i.01 to i32<br>+  call void @bar(i32 %conv2) #1<br>+  %inc = add i16 %i.01, 1<br>+;CHECK-NOT: %lftr.wideiv = trunc i32 %indvars.iv.next to i16<br>+;CHECK: %exitcond = icmp ne i32 %indvars.iv.next, 512<br>+  %cmp = icmp slt i16 %inc, 512<br>+  br i1 %cmp, label %for.body, label %for.end<br>+<br>+for.end:                                          ; preds = %for.body<br>+  ret void<br>+}<br>+<br>+declare void @bar(i32)<br>+<br>+attributes #0 = { nounwind uwtable }<br>+attributes #1 = { nounwind }<br><span><D1112.2.patch></span>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></body></html>