Fix a bug.
authorZhou Sheng <zhousheng00@gmail.com>
Wed, 27 Jun 2007 09:50:26 +0000 (09:50 +0000)
committerZhou Sheng <zhousheng00@gmail.com>
Wed, 27 Jun 2007 09:50:26 +0000 (09:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37751 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/IndVarSimplify.cpp

index f0019052d8f0b20092c80ac45254ee266d6f4b7f..01b74815f52e691923d7a719e7c93e4a591102b7 100644 (file)
@@ -519,8 +519,11 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
   DOUT << "INDVARS: New CanIV: " << *IndVar;
 
   if (!isa<SCEVCouldNotCompute>(IterationCount)) {
-    if (IterationCount->getType() != LargestType)
+    if (IterationCount->getType()->getPrimitiveSizeInBits() <
+        LargestType->getPrimitiveSizeInBits())
       IterationCount = SCEVZeroExtendExpr::get(IterationCount, LargestType);
+    else if (IterationCount->getType() != LargestType)
+      IterationCount = SCEVTruncateExpr::get(IterationCount, LargestType);
     if (Instruction *DI = LinearFunctionTestReplace(L, IterationCount,Rewriter))
       DeadInsts.insert(DI);
   }