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 @@ -1487,6 +1487,12 @@ /// triggers deletion of trivially dead istructions. void deleteAfterManifest(BasicBlock &BB) { ToBeDeletedBlocks.insert(&BB); } + // Record that \p BB is added during the manifest of an AA. Added basic blocks + // are preserved in the IR. + void registerManifestAddedBasicBlock(BasicBlock &BB) { + ManifestAddedBlocks.insert(&BB); + } + /// Record that \p F is deleted after information was manifested. void deleteAfterManifest(Function &F) { if (DeleteFns) @@ -1979,6 +1985,7 @@ ///{ SmallPtrSet ToBeDeletedFunctions; SmallPtrSet ToBeDeletedBlocks; + SmallPtrSet ManifestAddedBlocks; SmallDenseSet ToBeDeletedInsts; ///} diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -801,6 +801,9 @@ const IRPosition::CallBaseContext *CBCtx = QueryingAA ? QueryingAA->getCallBaseContext() : nullptr; + if (ManifestAddedBlocks.contains(I.getParent())) + return false; + if (!FnLivenessAA) FnLivenessAA = lookupAAFor(IRPosition::function(*I.getFunction(), CBCtx), @@ -1441,7 +1444,9 @@ << ToBeDeletedBlocks.size() << " blocks and " << ToBeDeletedInsts.size() << " instructions and " << ToBeChangedValues.size() << " values and " - << ToBeChangedUses.size() << " uses\n"); + << ToBeChangedUses.size() << " uses. " + << "Preserve manifest added " << ManifestAddedBlocks.size() + << " blocks\n"); SmallVector DeadInsts; SmallVector TerminatorsToFold; @@ -1602,6 +1607,9 @@ assert(isRunOn(*BB->getParent()) && "Cannot delete a block outside the current SCC!"); CGModifiedFunctions.insert(BB->getParent()); + // Do not delete BBs added during manifests of AAs. + if (ManifestAddedBlocks.contains(BB)) + continue; ToBeDeletedBBs.push_back(BB); } // Actually we do not delete the blocks but squash them into a single