[llvm] 0cfea5b - [BitcodeReader] Avoid quadratic complexity in intrinsic upgrade (#150032)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 00:52:08 PDT 2025
Author: Nikita Popov
Date: 2025-07-23T09:52:05+02:00
New Revision: 0cfea5b73cadfcf408f3549ff209fba4f56f9138
URL: https://github.com/llvm/llvm-project/commit/0cfea5b73cadfcf408f3549ff209fba4f56f9138
DIFF: https://github.com/llvm/llvm-project/commit/0cfea5b73cadfcf408f3549ff209fba4f56f9138.diff
LOG: [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.
Added:
Modified:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index f76368357a9c3..290d873c632c9 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);
+ }
}
}
More information about the llvm-commits
mailing list