diff options
| author | Nikita Popov <npopov@redhat.com> | 2025-07-23 09:52:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-23 09:52:05 +0200 |
| commit | 0cfea5b73cadfcf408f3549ff209fba4f56f9138 (patch) | |
| tree | 7146fda912c40d21ec45290dfea28edd940891a7 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
| parent | b59aaf7da7a7121bf0263243fcec6a5fd6db1a2b (diff) | |
[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.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
| -rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index f76368357a9c..290d873c632c 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -7015,13 +7015,6 @@ Error BitcodeReader::materialize(GlobalValue *GV) { if (StripDebugInfo) stripDebugInfo(*F); - // Upgrade any old intrinsic calls in the function. - for (auto &I : UpgradedIntrinsics) { - for (User *U : llvm::make_early_inc_range(I.first->materialized_users())) - if (CallInst *CI = dyn_cast<CallInst>(U)) - UpgradeIntrinsicCall(CI, I.second); - } - // Finish fn->subprogram upgrade for materialized functions. if (DISubprogram *SP = MDLoader->lookupSubprogramForFunction(F)) F->setSubprogram(SP); @@ -7037,7 +7030,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) { } } - for (auto &I : instructions(F)) { + for (auto &I : make_early_inc_range(instructions(F))) { // "Upgrade" older incorrect branch weights by dropping them. if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) { if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) { @@ -7068,8 +7061,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) { } } - // Remove incompatible attributes on function calls. if (auto *CI = dyn_cast<CallBase>(&I)) { + // Remove incompatible attributes on function calls. CI->removeRetAttrs(AttributeFuncs::typeIncompatible( CI->getFunctionType()->getReturnType(), CI->getRetAttributes())); @@ -7077,6 +7070,13 @@ Error BitcodeReader::materialize(GlobalValue *GV) { CI->removeParamAttrs(ArgNo, AttributeFuncs::typeIncompatible( CI->getArgOperand(ArgNo)->getType(), CI->getParamAttributes(ArgNo))); + + // Upgrade intrinsics. + if (Function *OldFn = CI->getCalledFunction()) { + auto It = UpgradedIntrinsics.find(OldFn); + if (It != UpgradedIntrinsics.end()) + UpgradeIntrinsicCall(CI, It->second); + } } } |
