<div dir="ltr">Hi Hans,<div><br></div><div>Can we get this merged in?</div><div><br></div><div>Thanks</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 5:58 PM, Sanjoy Das via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sanjoy<br>
Date: Fri Aug 12 19:58:31 2016<br>
New Revision: 278584<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278584&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278584&view=rev</a><br>
Log:<br>
[IndVars] Ignore (s|z)exts that don't extend the induction variable<br>
<br>
`IVVisitor::visitCast` used to have the invariant that if the<br>
instruction it was passed was a sext or zext instruction, the result of<br>
the instruction would be wider than the induction variable.  This is no<br>
longer true after rL275037, so this change teaches `IndVarSimplify` s<br>
implementation of `IVVisitor::visitCast` to work with the relaxed<br>
invariant.<br>
<br>
A corresponding change to SimplifyIndVar to preserve the said invariant<br>
after rL275037 would also work, but given how `IVVisitor::visitCast` is<br>
spelled (no indication of said invariant), I figured the current fix is<br>
cleaner.<br>
<br>
Fixes PR28935.<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/<wbr>IndVarSimplify/pr28935.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/<wbr>Scalar/IndVarSimplify.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>Scalar/IndVarSimplify.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=278584&r1=278583&r2=278584&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Scalar/<wbr>IndVarSimplify.cpp?rev=278584&<wbr>r1=278583&r2=278584&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>Scalar/IndVarSimplify.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>Scalar/IndVarSimplify.cpp Fri Aug 12 19:58:31 2016<br>
@@ -816,6 +816,14 @@ static void visitIVCast(CastInst *Cast,<br>
   if (!Cast->getModule()-><wbr>getDataLayout().<wbr>isLegalInteger(Width))<br>
     return;<br>
<br>
+  // Check that `Cast` actually extends the induction variable (we rely on this<br>
+  // later).  This takes care of cases where `Cast` is extending a truncation of<br>
+  // the narrow induction variable, and thus can end up being narrower than the<br>
+  // "narrow" induction variable.<br>
+  uint64_t NarrowIVWidth = SE->getTypeSizeInBits(WI.<wbr>NarrowIV->getType());<br>
+  if (NarrowIVWidth >= Width)<br>
+    return;<br>
+<br>
   // Cast is either an sext or zext up to this point.<br>
   // We should not widen an indvar if arithmetics on the wider indvar are more<br>
   // expensive than those on the narrower indvar. We check only the cost of ADD<br>
<br>
Added: llvm/trunk/test/Transforms/<wbr>IndVarSimplify/pr28935.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/pr28935.ll?rev=278584&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Transforms/IndVarSimplify/<wbr>pr28935.ll?rev=278584&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Transforms/<wbr>IndVarSimplify/pr28935.ll (added)<br>
+++ llvm/trunk/test/Transforms/<wbr>IndVarSimplify/pr28935.ll Fri Aug 12 19:58:31 2016<br>
@@ -0,0 +1,20 @@<br>
+; RUN: opt -S -indvars < %s | FileCheck %s<br>
+<br>
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:<wbr>32:64-S128"<br>
+target triple = "x86_64-unknown-linux-gnu"<br>
+<br>
+declare i16 @fn1(i16 returned, i64)<br>
+<br>
+define void @fn2() {<br>
+; CHECK-LABEL: @fn2(<br>
+entry:<br>
+  br label %for.cond<br>
+<br>
+for.cond:<br>
+  %f.0 = phi i64 [ undef, %entry ], [ %inc, %for.cond ]<br>
+  %conv = trunc i64 %f.0 to i16<br>
+  %call = tail call i16 @fn1(i16 %conv, i64 %f.0)<br>
+  %conv2 = zext i16 %call to i32<br>
+  %inc = add nsw i64 %f.0, 1<br>
+  br label %for.cond<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>