summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-13 21:50:52 +0000
committerChris Lattner <sabre@nondot.org>2003-05-13 21:50:52 +0000
commit0ec3590664dda705ac9039de403460cca5b947c1 (patch)
tree7a44246f486c3d68129fa0d217d84a0c5286d83e /lib/VMCore
parent9bc02a4debba3b279350235a198f651be5d2722e (diff)
downloadllvm-0ec3590664dda705ac9039de403460cca5b947c1.tar.gz
llvm-0ec3590664dda705ac9039de403460cca5b947c1.tar.bz2
llvm-0ec3590664dda705ac9039de403460cca5b947c1.tar.xz
Implement another getelementptr folding opportunity that arises when
linking stuff with appending linkage git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6180 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/ConstantFold.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 8da98f1997..ee5611ea7d 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -150,6 +150,22 @@ Constant *ConstantFoldGetElementPtr(const Constant *C,
// 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;
}