diff options
author | Dan Gohman <gohman@apple.com> | 2010-03-10 19:31:51 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-03-10 19:31:51 +0000 |
commit | 0891d752a68a25025ffc3339aab1f0ad3221b0ed (patch) | |
tree | e6f41777ed0f31f39207bf7e1a2abef754eacc14 /lib/Analysis/ConstantFolding.cpp | |
parent | a77338476f55c2034abee901c5cd2955641bc990 (diff) |
Constant-fold GEP-of-GEP into a single GEP.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98178 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 114db2d370..62020afb72 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -589,6 +589,17 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps, APInt Offset = APInt(BitWidth, TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1)); + + // If this is a GEP of a GEP, fold it all into a single GEP. + while (GEPOperator *GEP = dyn_cast<GEPOperator>(Ptr)) { + SmallVector<Value *, 4> NestedOps(GEP->op_begin()+1, GEP->op_end()); + Ptr = cast<Constant>(GEP->getOperand(0)); + Offset += APInt(BitWidth, + TD->getIndexedOffset(Ptr->getType(), + (Value**)NestedOps.data(), + NestedOps.size())); + } + // If the base value for this address is a literal integer value, fold the // getelementptr to the resulting integer value casted to the pointer type. if (BaseIsInt) { |