diff options
| author | Chris Lattner <sabre@nondot.org> | 2003-08-21 19:45:55 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2003-08-21 19:45:55 +0000 |
| commit | 941b06bf3c12bc04e19593ca9e3e886655f937d5 (patch) | |
| tree | d17914e7e8f3f62acc91369b60773c4cffad9d34 /llvm/lib/VMCore/ConstantHandling.cpp | |
| parent | 3b156bb2a51c8397968a9e8fafd8502cb075f371 (diff) | |
| download | bcm5719-llvm-941b06bf3c12bc04e19593ca9e3e886655f937d5.tar.gz bcm5719-llvm-941b06bf3c12bc04e19593ca9e3e886655f937d5.zip | |
Implement Assembler/2003-08-21-ConstantExprCast-Fold.llx
llvm-svn: 8015
Diffstat (limited to 'llvm/lib/VMCore/ConstantHandling.cpp')
| -rw-r--r-- | llvm/lib/VMCore/ConstantHandling.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/ConstantHandling.cpp b/llvm/lib/VMCore/ConstantHandling.cpp index 85a89de145a..956397701ff 100644 --- a/llvm/lib/VMCore/ConstantHandling.cpp +++ b/llvm/lib/VMCore/ConstantHandling.cpp @@ -95,6 +95,17 @@ Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy) { if (S1 <= S2 && S2 >= S3 && S1 <= S3) return ConstantExpr::getCast(Op, DestTy); } + } else if (CE->getOpcode() == Instruction::GetElementPtr) { + // If all of the indexes in the GEP are null values, there is no pointer + // adjustment going on. We might as well cast the source pointer. + bool isAllNull = true; + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + if (!CE->getOperand(i)->isNullValue()) { + isAllNull = false; + break; + } + if (isAllNull) + return ConstantExpr::getCast(CE->getOperand(0), DestTy); } return ConstRules::get(*V, *V)->castTo(V, DestTy); @@ -137,9 +148,8 @@ Constant *ConstantFoldGetElementPtr(const Constant *C, (IdxList.size() == 1 && IdxList[0]->isNullValue())) return const_cast<Constant*>(C); - // If C is null and all idx's are null, return null of the right type. + // TODO 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 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { // Combine Indices - If the source pointer to this getelementptr instruction |

