Skip to content

Commit 0ece283

Browse files
committed
[Attributor] Add checks needed as we strengthen value simplify
1 parent 393be12 commit 0ece283

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,12 @@ ChangeStatus Attributor::cleanupIR() {
20022002
for (auto &U : OldV->uses())
20032003
if (Entry.second || !U.getUser()->isDroppable())
20042004
Uses.push_back(&U);
2005-
for (Use *U : Uses)
2005+
for (Use *U : Uses) {
2006+
if (auto *I = dyn_cast<Instruction>(U->getUser()))
2007+
if (!isRunOn(*I->getFunction()))
2008+
continue;
20062009
ReplaceUse(U, NewV);
2010+
}
20072011
}
20082012

20092013
for (auto &V : InvokeWithDeadSuccessor)

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,8 +4895,13 @@ struct AAInstanceInfoImpl : public AAInstanceInfo {
48954895
const auto &ArgInstanceInfoAA = A.getAAFor<AAInstanceInfo>(
48964896
*this, IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)),
48974897
DepClassTy::OPTIONAL);
4898-
if (ArgInstanceInfoAA.isAssumedUniqueForAnalysis())
4899-
return true;
4898+
if (!ArgInstanceInfoAA.isAssumedUniqueForAnalysis())
4899+
return false;
4900+
// If this call base might reach the scope again we might forward the
4901+
// argument back here. This is very conservative.
4902+
if (AA::isPotentiallyReachable(A, *CB, *Scope, *this, nullptr))
4903+
return false;
4904+
return true;
49004905
}
49014906
return false;
49024907
};
@@ -5201,6 +5206,8 @@ ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) {
52015206
// AAReturnedValues, e.g., track all values that escape through returns
52025207
// directly somehow.
52035208
auto CheckReturnedArgs = [&](const AAReturnedValues &RVAA) {
5209+
if (!RVAA.getState().isValidState())
5210+
return false;
52045211
bool SeenConstant = false;
52055212
for (auto &It : RVAA.returned_values()) {
52065213
if (isa<Constant>(It.first)) {
@@ -6433,6 +6440,8 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
64336440
dbgs() << "[H2S] unique free call might free unknown allocations\n");
64346441
return false;
64356442
}
6443+
if (DI->PotentialAllocationCalls.empty())
6444+
return true;
64366445
if (DI->PotentialAllocationCalls.size() > 1) {
64376446
LLVM_DEBUG(dbgs() << "[H2S] unique free call might free "
64386447
<< DI->PotentialAllocationCalls.size()

0 commit comments

Comments
 (0)