When folding constant expr gep's, don't force the use of long indices.
authorChris Lattner <sabre@nondot.org>
Wed, 7 Jul 2004 04:45:13 +0000 (04:45 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 7 Jul 2004 04:45:13 +0000 (04:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14658 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index a57606669d3fa02ae6d6d552b9f9c068d0cf5b45..5a8e41c74ea30411c88051e9cce4f17a77bb77fd 100644 (file)
@@ -993,11 +993,14 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
         // Add the last index of the source with the first index of the new GEP.
         // Make sure to handle the case when they are actually different types.
         Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
-        if (!IdxList[0]->isNullValue())   // Otherwise it must be an array
+        if (!IdxList[0]->isNullValue()) {  // Otherwise it must be an array
+          const Type *IdxTy = Combined->getType();
+          if (IdxTy != IdxList[0]->getType()) IdxTy = Type::LongTy;
           Combined = 
             ConstantExpr::get(Instruction::Add,
-                              ConstantExpr::getCast(IdxList[0], Type::LongTy),
-                              ConstantExpr::getCast(Combined, Type::LongTy));
+                              ConstantExpr::getCast(IdxList[0], IdxTy),
+                              ConstantExpr::getCast(Combined, IdxTy));
+        }
         
         NewIndices.push_back(Combined);
         NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());