Skip to content

Commit f58ab32

Browse files
jdoerferttstellar
authored andcommitted
[Attributor][FIX] Pipe UsedAssumedInformation through more interfaces
`UsedAssumedInformation` is a return argument utilized to determine what information is known. Most APIs used it already but `genericValueTraversal` did not. This adds it to `genericValueTraversal` and replaces `AllCallSitesKnown` of `checkForAllCallSites` with the commonly used `UsedAssumedInformation`. This was supposed to be a NFC commit, then the test change appeared. Turns out, we had one user of `AllCallSitesKnown` (AANoReturn) and the way we set `AllCallSitesKnown` was wrong as we ignored the fact some call sites were optimistically assumed dead. Included a dedicated test for this as well now. Fixes #53884
1 parent 4327d39 commit f58ab32

File tree

5 files changed

+143
-84
lines changed

5 files changed

+143
-84
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ bool getAssumedUnderlyingObjects(Attributor &A, const Value &Ptr,
192192
SmallVectorImpl<Value *> &Objects,
193193
const AbstractAttribute &QueryingAA,
194194
const Instruction *CtxI,
195+
bool &UsedAssumedInformation,
195196
bool Intraprocedural = false);
196197

197198
/// Collect all potential values of the one stored by \p SI into
@@ -1824,23 +1825,24 @@ struct Attributor {
18241825
/// This method will evaluate \p Pred on call sites and return
18251826
/// true if \p Pred holds in every call sites. However, this is only possible
18261827
/// all call sites are known, hence the function has internal linkage.
1827-
/// If true is returned, \p AllCallSitesKnown is set if all possible call
1828-
/// sites of the function have been visited.
1828+
/// If true is returned, \p UsedAssumedInformation is set if assumed
1829+
/// information was used to skip or simplify potential call sites.
18291830
bool checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
18301831
const AbstractAttribute &QueryingAA,
1831-
bool RequireAllCallSites, bool &AllCallSitesKnown);
1832+
bool RequireAllCallSites,
1833+
bool &UsedAssumedInformation);
18321834

18331835
/// Check \p Pred on all call sites of \p Fn.
18341836
///
18351837
/// This method will evaluate \p Pred on call sites and return
18361838
/// true if \p Pred holds in every call sites. However, this is only possible
18371839
/// all call sites are known, hence the function has internal linkage.
1838-
/// If true is returned, \p AllCallSitesKnown is set if all possible call
1839-
/// sites of the function have been visited.
1840+
/// If true is returned, \p UsedAssumedInformation is set if assumed
1841+
/// information was used to skip or simplify potential call sites.
18401842
bool checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
18411843
const Function &Fn, bool RequireAllCallSites,
18421844
const AbstractAttribute *QueryingAA,
1843-
bool &AllCallSitesKnown);
1845+
bool &UsedAssumedInformation);
18441846

18451847
/// Check \p Pred on all values potentially returned by \p F.
18461848
///

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ bool AA::getPotentialCopiesOfStoredValue(
320320

321321
Value &Ptr = *SI.getPointerOperand();
322322
SmallVector<Value *, 8> Objects;
323-
if (!AA::getAssumedUnderlyingObjects(A, Ptr, Objects, QueryingAA, &SI)) {
323+
if (!AA::getAssumedUnderlyingObjects(A, Ptr, Objects, QueryingAA, &SI,
324+
UsedAssumedInformation)) {
324325
LLVM_DEBUG(
325326
dbgs() << "Underlying objects stored into could not be determined\n";);
326327
return false;
@@ -514,10 +515,10 @@ isPotentiallyReachable(Attributor &A, const Instruction &FromI,
514515
return true;
515516
};
516517

517-
bool AllCallSitesKnown;
518+
bool UsedAssumedInformation = false;
518519
Result = !A.checkForAllCallSites(CheckCallSite, *FromFn,
519520
/* RequireAllCallSites */ true,
520-
&QueryingAA, AllCallSitesKnown);
521+
&QueryingAA, UsedAssumedInformation);
521522
if (Result) {
522523
LLVM_DEBUG(dbgs() << "[AA] stepping back to call sites from " << *CurFromI
523524
<< " in @" << FromFn->getName()
@@ -1277,7 +1278,7 @@ bool Attributor::checkForAllUses(
12771278
bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
12781279
const AbstractAttribute &QueryingAA,
12791280
bool RequireAllCallSites,
1280-
bool &AllCallSitesKnown) {
1281+
bool &UsedAssumedInformation) {
12811282
// We can try to determine information from
12821283
// the call sites. However, this is only possible all call sites are known,
12831284
// hence the function has internal linkage.
@@ -1286,31 +1287,26 @@ bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
12861287
if (!AssociatedFunction) {
12871288
LLVM_DEBUG(dbgs() << "[Attributor] No function associated with " << IRP
12881289
<< "\n");
1289-
AllCallSitesKnown = false;
12901290
return false;
12911291
}
12921292

12931293
return checkForAllCallSites(Pred, *AssociatedFunction, RequireAllCallSites,
1294-
&QueryingAA, AllCallSitesKnown);
1294+
&QueryingAA, UsedAssumedInformation);
12951295
}
12961296

12971297
bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
12981298
const Function &Fn,
12991299
bool RequireAllCallSites,
13001300
const AbstractAttribute *QueryingAA,
1301-
bool &AllCallSitesKnown) {
1301+
bool &UsedAssumedInformation) {
13021302
if (RequireAllCallSites && !Fn.hasLocalLinkage()) {
13031303
LLVM_DEBUG(
13041304
dbgs()
13051305
<< "[Attributor] Function " << Fn.getName()
13061306
<< " has no internal linkage, hence not all call sites are known\n");
1307-
AllCallSitesKnown = false;
13081307
return false;
13091308
}
13101309

1311-
// If we do not require all call sites we might not see all.
1312-
AllCallSitesKnown = RequireAllCallSites;
1313-
13141310
SmallVector<const Use *, 8> Uses(make_pointer_range(Fn.uses()));
13151311
for (unsigned u = 0; u < Uses.size(); ++u) {
13161312
const Use &U = *Uses[u];
@@ -1322,7 +1318,6 @@ bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred,
13221318
dbgs() << "[Attributor] Check use: " << *U << " in " << *U.getUser()
13231319
<< "\n";
13241320
});
1325-
bool UsedAssumedInformation = false;
13261321
if (isAssumedDead(U, QueryingAA, nullptr, UsedAssumedInformation,
13271322
/* CheckBBLivenessOnly */ true)) {
13281323
LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n");
@@ -1795,15 +1790,15 @@ void Attributor::identifyDeadInternalFunctions() {
17951790
if (!F)
17961791
continue;
17971792

1798-
bool AllCallSitesKnown;
1793+
bool UsedAssumedInformation = false;
17991794
if (checkForAllCallSites(
18001795
[&](AbstractCallSite ACS) {
18011796
Function *Callee = ACS.getInstruction()->getFunction();
18021797
return ToBeDeletedFunctions.count(Callee) ||
18031798
(Functions.count(Callee) && Callee->hasLocalLinkage() &&
18041799
!LiveInternalFns.count(Callee));
18051800
},
1806-
*F, true, nullptr, AllCallSitesKnown)) {
1801+
*F, true, nullptr, UsedAssumedInformation)) {
18071802
continue;
18081803
}
18091804

@@ -2290,9 +2285,9 @@ bool Attributor::isValidFunctionSignatureRewrite(
22902285
}
22912286

22922287
// Avoid callbacks for now.
2293-
bool AllCallSitesKnown;
2288+
bool UsedAssumedInformation = false;
22942289
if (!checkForAllCallSites(CallSiteCanBeChanged, *Fn, true, nullptr,
2295-
AllCallSitesKnown)) {
2290+
UsedAssumedInformation)) {
22962291
LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite all call sites\n");
22972292
return false;
22982293
}
@@ -2305,7 +2300,6 @@ bool Attributor::isValidFunctionSignatureRewrite(
23052300

23062301
// Forbid must-tail calls for now.
23072302
// TODO:
2308-
bool UsedAssumedInformation = false;
23092303
auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(*Fn);
23102304
if (!checkForAllInstructionsImpl(nullptr, OpcodeInstMap, InstPred, nullptr,
23112305
nullptr, {Instruction::Call},
@@ -2514,9 +2508,9 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
25142508
};
25152509

25162510
// Use the CallSiteReplacementCreator to create replacement call sites.
2517-
bool AllCallSitesKnown;
2511+
bool UsedAssumedInformation = false;
25182512
bool Success = checkForAllCallSites(CallSiteReplacementCreator, *OldFn,
2519-
true, nullptr, AllCallSitesKnown);
2513+
true, nullptr, UsedAssumedInformation);
25202514
(void)Success;
25212515
assert(Success && "Assumed call site replacement to succeed!");
25222516

0 commit comments

Comments
 (0)