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.
// 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?
auto KnowAllElts = [&AggElts]() {
return all_of(AggElts,
[](Optional<Value *> Elt) { return Elt != NotFound; });
[](Optional<Instruction *> Elt) { return Elt != NotFound; });
};
int Depth = 0;
@ -816,7 +816,11 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
Depth < DepthLimit && CurrIVI && !KnowAllElts();
CurrIVI = dyn_cast<InsertValueInst>(CurrIVI->getAggregateOperand()),
++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();
// 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
// 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!
Optional<Value *> &Elt = AggElts[Indices.front()];
Optional<Instruction *> &Elt = AggElts[Indices.front()];
Elt = Elt.getValueOr(InsertedValue);
// 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 \p PredBB is provided, does PHI translation of an \p Elt first.
auto FindSourceAggregate =
[&](Value *Elt, unsigned EltIdx, Optional<BasicBlock *> UseBB,
[&](Instruction *Elt, unsigned EltIdx, Optional<BasicBlock *> UseBB,
Optional<BasicBlock *> PredBB) -> Optional<Value *> {
// For now(?), only deal with, at most, a single level of PHI indirection.
if (UseBB && PredBB)
Elt = Elt->DoPHITranslation(*UseBB, *PredBB);
Elt = dyn_cast<Instruction>(Elt->DoPHITranslation(*UseBB, *PredBB));
// FIXME: deal with multiple levels of PHI indirection?
// Did we find an extraction?
auto *EVI = dyn_cast<ExtractValueInst>(Elt);
auto *EVI = dyn_cast_or_null<ExtractValueInst>(Elt);
if (!EVI)
return NotFound;
@ -966,13 +970,8 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
// they all should be defined in the same basic block.
BasicBlock *UseBB = nullptr;
for (const Optional<Value *> &Elt : AggElts) {
// If this element's value was not defined by an instruction, ignore it.
auto *I = dyn_cast<Instruction>(*Elt);
if (!I)
continue;
// Otherwise, in which basic block is this instruction located?
BasicBlock *BB = I->getParent();
for (const Optional<Instruction *> &I : AggElts) {
BasicBlock *BB = (*I)->getParent();
// If it's the first instruction we've encountered, record the basic block.
if (!UseBB) {
UseBB = BB;