diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -1331,6 +1331,8 @@ /// Record that \p U is to be replaces with \p NV after information was /// manifested. This also triggers deletion of trivially dead istructions. bool changeUseAfterManifest(Use &U, Value &NV) { + if (!canChangeUse(U)) + return false; Value *&V = ToBeChangedUses[&U]; if (V && (V->stripPointerCasts() == NV.stripPointerCasts() || isa_and_nonnull(V))) @@ -1341,6 +1343,14 @@ return true; } + bool canChangeUse(Use &U) { + if (Functions.empty()) + return true; + if (auto *I = dyn_cast(U.getUser())) + return Functions.contains(I->getParent()->getParent()); + return false; + } + /// Helper function to replace all uses of \p V with \p NV. Return true if /// there is any change. The flag \p ChangeDroppable indicates if dropppable /// uses should be changed too. @@ -1348,7 +1358,7 @@ bool ChangeDroppable = true) { bool Changed = false; for (auto &U : V.uses()) - if (ChangeDroppable || !U.getUser()->isDroppable()) + if ((ChangeDroppable || !U.getUser()->isDroppable()) && canChangeUse(U)) Changed |= changeUseAfterManifest(U, NV); return Changed;