Continue improving support for ConstantDataAggregate, and use the

new methods recently added to (sometimes greatly!) simplify code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149024 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2012-01-26 02:32:04 +00:00
parent e150e2df42
commit d59ae907ee
5 changed files with 148 additions and 418 deletions
@@ -1270,24 +1270,16 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
return ReplaceInstUsesWith(EV, Agg);
if (Constant *C = dyn_cast<Constant>(Agg)) {
if (isa<UndefValue>(C))
return ReplaceInstUsesWith(EV, UndefValue::get(EV.getType()));
if (isa<ConstantAggregateZero>(C))
return ReplaceInstUsesWith(EV, Constant::getNullValue(EV.getType()));
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
// Extract the element indexed by the first index out of the constant
Value *V = C->getOperand(*EV.idx_begin());
if (EV.getNumIndices() > 1)
// Extract the remaining indices out of the constant indexed by the
// first index
return ExtractValueInst::Create(V, EV.getIndices().slice(1));
else
return ReplaceInstUsesWith(EV, V);
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 0; // Can't handle other constants
}
}
if (InsertValueInst *IV = dyn_cast<InsertValueInst>(Agg)) {
// We're extracting from an insertvalue instruction, compare the indices
const unsigned *exti, *exte, *insi, *inse;