diff options
| author | Chris Lattner <sabre@nondot.org> | 2003-05-13 21:50:52 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2003-05-13 21:50:52 +0000 |
| commit | c2ceed1b389b14e6c366624860f691b70f1e4228 (patch) | |
| tree | 09c41a123a569b26ed46081321585c8084f8af45 /llvm/lib/VMCore/ConstantHandling.cpp | |
| parent | 2b383d2ef27cabf639719a3a9cc24e9ba9663fcc (diff) | |
| download | bcm5719-llvm-c2ceed1b389b14e6c366624860f691b70f1e4228.tar.gz bcm5719-llvm-c2ceed1b389b14e6c366624860f691b70f1e4228.zip | |
Implement another getelementptr folding opportunity that arises when
linking stuff with appending linkage
llvm-svn: 6180
Diffstat (limited to 'llvm/lib/VMCore/ConstantHandling.cpp')
| -rw-r--r-- | llvm/lib/VMCore/ConstantHandling.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantHandling.cpp b/llvm/lib/VMCore/ConstantHandling.cpp index 8da98f19979..ee5611ea7de 100644 --- a/llvm/lib/VMCore/ConstantHandling.cpp +++ b/llvm/lib/VMCore/ConstantHandling.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; } |

