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

Chris Lattner lattner at cs.uiuc.edu
Tue May 13 16:52:01 PDT 2003


Changes in directory llvm/lib/VMCore:

ConstantHandling.cpp updated: 1.27 -> 1.28

---
Log message:

Implement another getelementptr folding opportunity that arises when
linking stuff with appending linkage


---
Diffs of the changes:

Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.27 llvm/lib/VMCore/ConstantHandling.cpp:1.28
--- llvm/lib/VMCore/ConstantHandling.cpp:1.27	Mon May 12 10:26:25 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp	Tue May 13 16:50:52 2003
@@ -150,6 +150,22 @@
   // If C is null and all idx's are null, return null of the right type.
 
   // FIXME: Implement folding of GEP constant exprs the same as instcombine does
+
+  // Implement folding of:
+  //    int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
+  //                        long 0, long 0)
+  // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
+  //
+  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
+    if (CE->getOpcode() == Instruction::Cast && IdxList.size() > 1)
+      if (const PointerType *SPT = 
+          dyn_cast<PointerType>(CE->getOperand(0)->getType()))
+        if (const ArrayType *SAT = dyn_cast<ArrayType>(SPT->getElementType()))
+          if (const ArrayType *CAT =
+              dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
+            if (CAT->getElementType() == SAT->getElementType())
+              return ConstantExpr::getGetElementPtr(
+                      (Constant*)cast<Constant>(CE->getOperand(0)), IdxList);
   return 0;
 }
 





More information about the llvm-commits mailing list