diff options
author | Frits van Bommel <fvbommel@gmail.com> | 2010-11-29 20:36:52 +0000 |
---|---|---|
committer | Frits van Bommel <fvbommel@gmail.com> | 2010-11-29 20:36:52 +0000 |
commit | 3ee0af35842999c1781052fe74fdcb19997de950 (patch) | |
tree | f12d8cc7508c40d9fbd707d252b451b97ace43c6 /lib/Analysis/ConstantFolding.cpp | |
parent | 53ca1f3190680f3e86aebe0f72f7918d63f71e0d (diff) |
Teach ConstantFoldInstruction() how to fold insertvalue and extractvalue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index a5804208c4..70ee9ddfa6 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -740,7 +740,18 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const TargetData *TD) { if (const LoadInst *LI = dyn_cast<LoadInst>(I)) return ConstantFoldLoadInst(LI, TD); - + + if (InsertValueInst *IVI = dyn_cast<InsertValueInst>(I)) + return ConstantExpr::getInsertValue( + cast<Constant>(IVI->getAggregateOperand()), + cast<Constant>(IVI->getInsertedValueOperand()), + IVI->idx_begin(), IVI->getNumIndices()); + + if (ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I)) + return ConstantExpr::getExtractValue( + cast<Constant>(EVI->getAggregateOperand()), + EVI->idx_begin(), EVI->getNumIndices()); + return ConstantFoldInstOperands(I->getOpcode(), I->getType(), Ops.data(), Ops.size(), TD); } |