[IndVars] Fix PR24783.
[oota-llvm.git] / lib / Transforms / Scalar / IndVarSimplify.cpp
index c9fcf8ddf56f8be211300075894ff27ec950cfcf..73b8052961c33147f8d70b63f492c99772e53a7a 100644 (file)
@@ -509,7 +509,8 @@ Value *IndVarSimplify::ExpandSCEVIfNeeded(SCEVExpander &Rewriter, const SCEV *S,
   // Before expanding S into an expensive LLVM expression, see if we can use an
   // already existing value as the expansion for S.
   if (Value *ExistingValue = Rewriter.findExistingExpansion(S, InsertPt, L))
-    return ExistingValue;
+    if (ExistingValue->getType() == ResultTy)
+      return ExistingValue;
 
   // We didn't find anything, fall back to using SCEVExpander.
   return Rewriter.expandCodeFor(S, ResultTy, InsertPt);