Skip to content

Commit 0cfea5b

Browse files
authored
[BitcodeReader] Avoid quadratic complexity in intrinsic upgrade (#150032)
When materializing a function, we'd upgrade all calls to all upgraded intrinsics. However, this would operate on all calls to the intrinsic (including previously materialized ones), which leads to quadratic complexity. Instead, only upgrade the calls that are in the materialized function. This fixes a compile-time regression introduced by #149310.
1 parent b59aaf7 commit 0cfea5b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7015,13 +7015,6 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
70157015
if (StripDebugInfo)
70167016
stripDebugInfo(*F);
70177017

7018-
// Upgrade any old intrinsic calls in the function.
7019-
for (auto &I : UpgradedIntrinsics) {
7020-
for (User *U : llvm::make_early_inc_range(I.first->materialized_users()))
7021-
if (CallInst *CI = dyn_cast<CallInst>(U))
7022-
UpgradeIntrinsicCall(CI, I.second);
7023-
}
7024-
70257018
// Finish fn->subprogram upgrade for materialized functions.
70267019
if (DISubprogram *SP = MDLoader->lookupSubprogramForFunction(F))
70277020
F->setSubprogram(SP);
@@ -7037,7 +7030,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
70377030
}
70387031
}
70397032

7040-
for (auto &I : instructions(F)) {
7033+
for (auto &I : make_early_inc_range(instructions(F))) {
70417034
// "Upgrade" older incorrect branch weights by dropping them.
70427035
if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) {
70437036
if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) {
@@ -7068,15 +7061,22 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
70687061
}
70697062
}
70707063

7071-
// Remove incompatible attributes on function calls.
70727064
if (auto *CI = dyn_cast<CallBase>(&I)) {
7065+
// Remove incompatible attributes on function calls.
70737066
CI->removeRetAttrs(AttributeFuncs::typeIncompatible(
70747067
CI->getFunctionType()->getReturnType(), CI->getRetAttributes()));
70757068

70767069
for (unsigned ArgNo = 0; ArgNo < CI->arg_size(); ++ArgNo)
70777070
CI->removeParamAttrs(ArgNo, AttributeFuncs::typeIncompatible(
70787071
CI->getArgOperand(ArgNo)->getType(),
70797072
CI->getParamAttributes(ArgNo)));
7073+
7074+
// Upgrade intrinsics.
7075+
if (Function *OldFn = CI->getCalledFunction()) {
7076+
auto It = UpgradedIntrinsics.find(OldFn);
7077+
if (It != UpgradedIntrinsics.end())
7078+
UpgradeIntrinsicCall(CI, It->second);
7079+
}
70807080
}
70817081
}
70827082

0 commit comments

Comments
 (0)