1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 13:11:39 +01:00

[NFC][InstCombine] foldAggregateConstructionIntoAggregateReuse(): cast to Instruction eagerly

In all of these, the value must be an instruction for us to succeed anyway,
so change it to maybe hopefully make further changes more straight-forward.
This commit is contained in:
Roman Lebedev 2021-06-29 13:25:32 +03:00
parent 112f77cc7c
commit 35e351f514

View File

@ -796,12 +796,12 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
// Try to find a value of each element of an aggregate. // Try to find a value of each element of an aggregate.
// FIXME: deal with more complex, not one-dimensional, aggregate types // FIXME: deal with more complex, not one-dimensional, aggregate types
SmallVector<Optional<Value *>, 2> AggElts(NumAggElts, NotFound); SmallVector<Optional<Instruction *>, 2> AggElts(NumAggElts, NotFound);
// Do we know values for each element of the aggregate? // Do we know values for each element of the aggregate?
auto KnowAllElts = [&AggElts]() { auto KnowAllElts = [&AggElts]() {
return all_of(AggElts, return all_of(AggElts,
[](Optional<Value *> Elt) { return Elt != NotFound; }); [](Optional<Instruction *> Elt) { return Elt != NotFound; });
}; };
int Depth = 0; int Depth = 0;
@ -816,7 +816,11 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
Depth < DepthLimit && CurrIVI && !KnowAllElts(); Depth < DepthLimit && CurrIVI && !KnowAllElts();
CurrIVI = dyn_cast<InsertValueInst>(CurrIVI->getAggregateOperand()), CurrIVI = dyn_cast<InsertValueInst>(CurrIVI->getAggregateOperand()),
++Depth) { ++Depth) {
Value *InsertedValue = CurrIVI->getInsertedValueOperand(); auto *InsertedValue =
dyn_cast<Instruction>(CurrIVI->getInsertedValueOperand());
if (!InsertedValue)
return nullptr; // Inserted value must be produced by an instruction.
ArrayRef<unsigned int> Indices = CurrIVI->getIndices(); ArrayRef<unsigned int> Indices = CurrIVI->getIndices();
// Don't bother with more than single-level aggregates. // Don't bother with more than single-level aggregates.
@ -826,7 +830,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
// Now, we may have already previously recorded the value for this element // Now, we may have already previously recorded the value for this element
// of an aggregate. If we did, that means the CurrIVI will later be // of an aggregate. If we did, that means the CurrIVI will later be
// overwritten with the already-recorded value. But if not, let's record it! // overwritten with the already-recorded value. But if not, let's record it!
Optional<Value *> &Elt = AggElts[Indices.front()]; Optional<Instruction *> &Elt = AggElts[Indices.front()];
Elt = Elt.getValueOr(InsertedValue); Elt = Elt.getValueOr(InsertedValue);
// FIXME: should we handle chain-terminating undef base operand? // FIXME: should we handle chain-terminating undef base operand?
@ -870,15 +874,15 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
// If found, return the source aggregate from which the extraction was. // If found, return the source aggregate from which the extraction was.
// If \p PredBB is provided, does PHI translation of an \p Elt first. // If \p PredBB is provided, does PHI translation of an \p Elt first.
auto FindSourceAggregate = auto FindSourceAggregate =
[&](Value *Elt, unsigned EltIdx, Optional<BasicBlock *> UseBB, [&](Instruction *Elt, unsigned EltIdx, Optional<BasicBlock *> UseBB,
Optional<BasicBlock *> PredBB) -> Optional<Value *> { Optional<BasicBlock *> PredBB) -> Optional<Value *> {
// For now(?), only deal with, at most, a single level of PHI indirection. // For now(?), only deal with, at most, a single level of PHI indirection.
if (UseBB && PredBB) if (UseBB && PredBB)
Elt = Elt->DoPHITranslation(*UseBB, *PredBB); Elt = dyn_cast<Instruction>(Elt->DoPHITranslation(*UseBB, *PredBB));
// FIXME: deal with multiple levels of PHI indirection? // FIXME: deal with multiple levels of PHI indirection?
// Did we find an extraction? // Did we find an extraction?
auto *EVI = dyn_cast<ExtractValueInst>(Elt); auto *EVI = dyn_cast_or_null<ExtractValueInst>(Elt);
if (!EVI) if (!EVI)
return NotFound; return NotFound;
@ -966,13 +970,8 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
// they all should be defined in the same basic block. // they all should be defined in the same basic block.
BasicBlock *UseBB = nullptr; BasicBlock *UseBB = nullptr;
for (const Optional<Value *> &Elt : AggElts) { for (const Optional<Instruction *> &I : AggElts) {
// If this element's value was not defined by an instruction, ignore it. BasicBlock *BB = (*I)->getParent();
auto *I = dyn_cast<Instruction>(*Elt);
if (!I)
continue;
// Otherwise, in which basic block is this instruction located?
BasicBlock *BB = I->getParent();
// If it's the first instruction we've encountered, record the basic block. // If it's the first instruction we've encountered, record the basic block.
if (!UseBB) { if (!UseBB) {
UseBB = BB; UseBB = BB;