Don't try to mix integers and pointers in an icmp instruction
authorDan Gohman <gohman@apple.com>
Thu, 30 Apr 2009 16:40:30 +0000 (16:40 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 30 Apr 2009 16:40:30 +0000 (16:40 +0000)
in getSCEVAtScope.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70495 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp
test/Transforms/LoopStrengthReduce/pr3086.ll

index 5302ea87de8c0bf6769479d7eb20edfd35d68250..027ce6ffe154be1ea6dea700204295bd71e88843 100644 (file)
@@ -2613,21 +2613,28 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
             // If any of the operands is non-constant and if they are
             // non-integer and non-pointer, don't even try to analyze them
             // with scev techniques.
-            if (!isa<IntegerType>(Op->getType()) &&
-                !isa<PointerType>(Op->getType()))
+            if (!isSCEVable(Op->getType()))
               return V;
 
             SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
-            if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV))
-              Operands.push_back(ConstantExpr::getIntegerCast(SC->getValue(), 
-                                                              Op->getType(), 
-                                                              false));
-            else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
-              if (Constant *C = dyn_cast<Constant>(SU->getValue()))
-                Operands.push_back(ConstantExpr::getIntegerCast(C, 
-                                                                Op->getType(), 
-                                                                false));
-              else
+            if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV)) {
+              Constant *C = SC->getValue();
+              if (C->getType() != Op->getType())
+                C = ConstantExpr::getCast(CastInst::getCastOpcode(C, false,
+                                                                  Op->getType(),
+                                                                  false),
+                                          C, Op->getType());
+              Operands.push_back(C);
+            } else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
+              if (Constant *C = dyn_cast<Constant>(SU->getValue())) {
+                if (C->getType() != Op->getType())
+                  C =
+                    ConstantExpr::getCast(CastInst::getCastOpcode(C, false,
+                                                                  Op->getType(),
+                                                                  false),
+                                          C, Op->getType());
+                Operands.push_back(C);
+              } else
                 return V;
             } else {
               return V;
index 4ca333f614612d41b89909d9e7143bbda667ca8c..f92bfe2b68c859d066771c1dd1a8d84daca94100 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: llvm-as < %s | opt -loop-reduce -disable-output
+; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output
 ; PR 3086
 
        %struct.Cls = type { i32, i8, [2 x %struct.Cls*], [2 x %struct.Lit*] }