[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 6 23:46:01 PDT 2004


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.59 -> 1.60

---
Log message:

When folding constant expr gep's, don't force the use of long indices.


---
Diffs of the changes:  (+6 -3)

Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.59 llvm/lib/VMCore/ConstantFolding.cpp:1.60
--- llvm/lib/VMCore/ConstantFolding.cpp:1.59	Thu Jun 17 13:18:53 2004
+++ llvm/lib/VMCore/ConstantFolding.cpp	Tue Jul  6 23:45:13 2004
@@ -993,11 +993,14 @@
         // 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());





More information about the llvm-commits mailing list