[llvm-branch-commits] [llvm-branch] r278685 - Merging r278584:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 15 10:29:30 PDT 2016


Author: hans
Date: Mon Aug 15 12:29:29 2016
New Revision: 278685

URL: http://llvm.org/viewvc/llvm-project?rev=278685&view=rev
Log:
Merging r278584:
------------------------------------------------------------------------
r278584 | sanjoy | 2016-08-12 17:58:31 -0700 (Fri, 12 Aug 2016) | 15 lines

[IndVars] Ignore (s|z)exts that don't extend the induction variable

`IVVisitor::visitCast` used to have the invariant that if the
instruction it was passed was a sext or zext instruction, the result of
the instruction would be wider than the induction variable.  This is no
longer true after rL275037, so this change teaches `IndVarSimplify` s
implementation of `IVVisitor::visitCast` to work with the relaxed
invariant.

A corresponding change to SimplifyIndVar to preserve the said invariant
after rL275037 would also work, but given how `IVVisitor::visitCast` is
spelled (no indication of said invariant), I figured the current fix is
cleaner.

Fixes PR28935.
------------------------------------------------------------------------

Added:
    llvm/branches/release_39/test/Transforms/IndVarSimplify/pr28935.ll
      - copied unchanged from r278584, llvm/trunk/test/Transforms/IndVarSimplify/pr28935.ll
Modified:
    llvm/branches/release_39/   (props changed)
    llvm/branches/release_39/lib/Transforms/Scalar/IndVarSimplify.cpp

Propchange: llvm/branches/release_39/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 15 12:29:29 2016
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,275868-275870,275879,275898,275928,275935,275946,275978,275981,276015,276051,276077,276109,276119,276181,276209,276236-276237,276358,276364,276368,276389,276435,276438,276479,276510,276648,276676,276712,276740,276823,276956,276980,277093,277114,277135,277371,277399,277500,277504,277625,277691,277693,277773,278002,278086,278133,278157,278370,278413,278569,278573
+/llvm/trunk:155241,275868-275870,275879,275898,275928,275935,275946,275978,275981,276015,276051,276077,276109,276119,276181,276209,276236-276237,276358,276364,276368,276389,276435,276438,276479,276510,276648,276676,276712,276740,276823,276956,276980,277093,277114,277135,277371,277399,277500,277504,277625,277691,277693,277773,278002,278086,278133,278157,278370,278413,278569,278573,278584

Modified: llvm/branches/release_39/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=278685&r1=278684&r2=278685&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Aug 15 12:29:29 2016
@@ -815,6 +815,14 @@ static void visitIVCast(CastInst *Cast,
   if (!Cast->getModule()->getDataLayout().isLegalInteger(Width))
     return;
 
+  // Check that `Cast` actually extends the induction variable (we rely on this
+  // later).  This takes care of cases where `Cast` is extending a truncation of
+  // the narrow induction variable, and thus can end up being narrower than the
+  // "narrow" induction variable.
+  uint64_t NarrowIVWidth = SE->getTypeSizeInBits(WI.NarrowIV->getType());
+  if (NarrowIVWidth >= Width)
+    return;
+
   // Cast is either an sext or zext up to this point.
   // We should not widen an indvar if arithmetics on the wider indvar are more
   // expensive than those on the narrower indvar. We check only the cost of ADD




More information about the llvm-branch-commits mailing list