SILOptimizer: update bounds check and uniqueness check hoisting optimizations for using _modify in Array subscript.

The optimizations now handle the ref_tail_addr instructions for detecting element addresses
(in addition to the array semantics function _getElementAddress).
After _modify for Array subscript lands, we can get rid of _getElementAddress at all.
This commit is contained in:
Erik Eckstein
2018-09-06 16:58:06 -07:00
parent aca5ae8fb7
commit 584ed9710f
5 changed files with 109 additions and 53 deletions

View File

@@ -798,20 +798,6 @@ bool COWArrayOpt::checkSafeElementValueUses(UserOperList &ElementValueUsers) {
}
return true;
}
static bool isArrayEltStore(StoreInst *SI) {
SILValue Dest = stripAddressProjections(SI->getDest());
if (auto *MD = dyn_cast<MarkDependenceInst>(Dest))
Dest = MD->getValue();
if (auto *PtrToAddr =
dyn_cast<PointerToAddressInst>(stripAddressProjections(Dest)))
if (auto *SEI = dyn_cast<StructExtractInst>(PtrToAddr->getOperand())) {
ArraySemanticsCall Call(SEI->getOperand());
if (Call && Call.getKind() == ArrayCallKind::kGetElementAddress)
return true;
}
return false;
}
/// Check whether the array semantic operation could change an array value to
/// not be uniquely referenced.
@@ -1278,7 +1264,7 @@ bool COWArrayOpt::hoistInLoopWithOnlyNonArrayValueMutatingOperations() {
// A store is only safe if it is to an array element and the element type
// is trivial.
if (auto *SI = dyn_cast<StoreInst>(Inst)) {
if (!isArrayEltStore(SI) ||
if (!isAddressOfArrayElement(SI->getDest()) ||
!SI->getSrc()->getType().isTrivial(Module)) {
LLVM_DEBUG(llvm::dbgs()
<<" (NO) non trivial store could store an array value "
@@ -1420,7 +1406,7 @@ bool COWArrayOpt::hasLoopOnlyDestructorSafeArrayOperations() {
// Stores to array elements.
if (auto *SI = dyn_cast<StoreInst>(Inst)) {
if (isArrayEltStore(SI))
if (isAddressOfArrayElement(SI->getDest()))
continue;
LLVM_DEBUG(llvm::dbgs() << " (NO) unknown store " << *SI);
return ReturnWithCleanup(false);