[InstSimplify] Teach InstSimplify how to simplify extractvalue

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242007 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2015-07-13 01:15:46 +00:00
parent 6c57f2fe84
commit 5501985a58
5 changed files with 68 additions and 10 deletions

View File

@@ -2174,16 +2174,9 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
if (!EV.hasIndices())
return ReplaceInstUsesWith(EV, Agg);
if (Constant *C = dyn_cast<Constant>(Agg)) {
if (Constant *C2 = C->getAggregateElement(*EV.idx_begin())) {
if (EV.getNumIndices() == 0)
return ReplaceInstUsesWith(EV, C2);
// Extract the remaining indices out of the constant indexed by the
// first index
return ExtractValueInst::Create(C2, EV.getIndices().slice(1));
}
return nullptr; // Can't handle other constants
}
if (Value *V =
SimplifyExtractValueInst(Agg, EV.getIndices(), DL, TLI, DT, AC))
return ReplaceInstUsesWith(EV, V);
if (InsertValueInst *IV = dyn_cast<InsertValueInst>(Agg)) {
// We're extracting from an insertvalue instruction, compare the indices