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

Chris Lattner lattner at cs.uiuc.edu
Sun Jan 11 17:57:01 PST 2004


Changes in directory llvm/lib/VMCore:

ConstantHandling.cpp updated: 1.42 -> 1.43

---
Log message:

Implement: Assembler/2004-01-11-getelementptrfolding.llx


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

Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.42 llvm/lib/VMCore/ConstantHandling.cpp:1.43
--- llvm/lib/VMCore/ConstantHandling.cpp:1.42	Tue Nov 25 15:21:46 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp	Sun Jan 11 17:56:33 2004
@@ -171,7 +171,7 @@
            I != E; ++I)
         LastTy = *I;
 
-      if (LastTy && isa<ArrayType>(LastTy)) {
+      if ((LastTy && isa<ArrayType>(LastTy)) || IdxList[0]->isNullValue()) {
         std::vector<Constant*> NewIndices;
         NewIndices.reserve(IdxList.size() + CE->getNumOperands());
         for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
@@ -179,11 +179,13 @@
 
         // 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 =
-          ConstantExpr::get(Instruction::Add,
-                            ConstantExpr::getCast(IdxList[0], Type::LongTy),
-   ConstantExpr::getCast(CE->getOperand(CE->getNumOperands()-1), Type::LongTy));
-                            
+        Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
+        if (!IdxList[0]->isNullValue())   // Otherwise it must be an array
+          Combined = 
+            ConstantExpr::get(Instruction::Add,
+                              ConstantExpr::getCast(IdxList[0], Type::LongTy),
+                              ConstantExpr::getCast(Combined, Type::LongTy));
+        
         NewIndices.push_back(Combined);
         NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
         return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);





More information about the llvm-commits mailing list