Skip to content

Commit 5b3f128

Browse files
authored
Merge pull request #22041 from gottesmm/pr-6a1df2251889fc8954e6057a15e57e4ec130a20c
2 parents 7fbd1bf + 14a9dcb commit 5b3f128

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,14 @@ class AvailableValueAggregator {
423423
void print(llvm::raw_ostream &os) const;
424424
void dump() const LLVM_ATTRIBUTE_USED;
425425
private:
426-
SILValue aggregateFullyAvailableValue(SILType LoadTy, unsigned FirstElt);
427-
SILValue aggregateTupleSubElts(TupleType *TT, SILType LoadTy,
428-
SILValue Address, unsigned FirstElt);
429-
SILValue aggregateStructSubElts(StructDecl *SD, SILType LoadTy,
430-
SILValue Address, unsigned FirstElt);
431-
SILValue handlePrimitiveValue(SILType LoadTy, SILValue Address,
432-
unsigned FirstElt);
426+
SILValue aggregateFullyAvailableValue(SILType loadTy, unsigned firstElt);
427+
SILValue aggregateTupleSubElts(TupleType *tt, SILType loadTy,
428+
SILValue address, unsigned firstElt);
429+
SILValue aggregateStructSubElts(StructDecl *sd, SILType loadTy,
430+
SILValue address, unsigned firstElt);
431+
SILValue handlePrimitiveValue(SILType loadTy, SILValue address,
432+
unsigned firstElt);
433+
bool isFullyAvailable(SILType loadTy, unsigned firstElt) const;
433434
};
434435

435436
} // end anonymous namespace
@@ -444,6 +445,26 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
444445
}
445446
}
446447

448+
bool AvailableValueAggregator::isFullyAvailable(SILType loadTy,
449+
unsigned firstElt) const {
450+
if (firstElt >= AvailableValueList.size()) { // #Elements may be zero.
451+
return false;
452+
}
453+
454+
auto &firstVal = AvailableValueList[firstElt];
455+
456+
// Make sure that the first element is available and is the correct type.
457+
if (!firstVal || firstVal.getType() != loadTy)
458+
return false;
459+
460+
return llvm::all_of(range(getNumSubElements(loadTy, M)),
461+
[&](unsigned index) -> bool {
462+
auto &val = AvailableValueList[firstElt + index];
463+
return val.getValue() == firstVal.getValue() &&
464+
val.getSubElementNumber() == index;
465+
});
466+
}
467+
447468
/// Given a bunch of primitive subelement values, build out the right aggregate
448469
/// type (LoadTy) by emitting tuple and struct instructions as necessary.
449470
SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
@@ -475,26 +496,13 @@ SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
475496
SILValue
476497
AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
477498
unsigned firstElt) {
478-
if (firstElt >= AvailableValueList.size()) { // #Elements may be zero.
499+
// Check if our underlying type is fully available. If it isn't, bail.
500+
if (!isFullyAvailable(loadTy, firstElt))
479501
return SILValue();
480-
}
481502

503+
// Ok, grab out first value. (note: any actually will do).
482504
auto &firstVal = AvailableValueList[firstElt];
483505

484-
// Make sure that the first element is available and is the correct type.
485-
if (!firstVal || firstVal.getType() != loadTy)
486-
return SILValue();
487-
488-
// If the first element of this value is available, check that any extra
489-
// available values are from the same place as our first value.
490-
if (llvm::any_of(range(getNumSubElements(loadTy, M)),
491-
[&](unsigned index) -> bool {
492-
auto &val = AvailableValueList[firstElt + index];
493-
return val.getValue() != firstVal.getValue() ||
494-
val.getSubElementNumber() != index;
495-
}))
496-
return SILValue();
497-
498506
// Ok, we know that all of our available values are all parts of the same
499507
// value. Without ownership, we can just return the underlying first value.
500508
if (!B.hasOwnership())

0 commit comments

Comments
 (0)