From b614ead3900d6d584ba7eff3f8eccebba24aec93 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 24 Sep 2025 10:18:08 +0200 Subject: [PATCH 1/2] [AssumptionCache] Don't use ResultElem for assumption list (NFC) ResultElem stores a weak handle of an assume, plus an index for referring to a specific operand bundle. This makes sense for the results of assumptionsFor(), which refers to specific operands of assumes. However, assumptions() is a plain list of assumes. It does not contain separate entries for each operand bundles. The operand bundle index is always ExprResultIdx. As such, we should be directly using WeakVH for this case, without the additional wrapper. --- llvm/include/llvm/Analysis/AssumptionCache.h | 4 ++-- llvm/lib/Analysis/AssumptionCache.cpp | 4 ++-- llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/Analysis/AssumptionCache.h b/llvm/include/llvm/Analysis/AssumptionCache.h index 1b026ef76a45e..be33be3bf2e87 100644 --- a/llvm/include/llvm/Analysis/AssumptionCache.h +++ b/llvm/include/llvm/Analysis/AssumptionCache.h @@ -65,7 +65,7 @@ class AssumptionCache { /// Vector of weak value handles to calls of the \@llvm.assume /// intrinsic. - SmallVector AssumeHandles; + SmallVector AssumeHandles; class LLVM_ABI AffectedValueCallbackVH final : public CallbackVH { AssumptionCache *AC; @@ -148,7 +148,7 @@ class AssumptionCache { /// FIXME: We should replace this with pointee_iterator> /// when we can write that to filter out the null values. Then caller code /// will become simpler. - MutableArrayRef assumptions() { + MutableArrayRef assumptions() { if (!Scanned) scanFunction(); return AssumeHandles; diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp index 980a891266e50..45ff9161db97c 100644 --- a/llvm/lib/Analysis/AssumptionCache.cpp +++ b/llvm/lib/Analysis/AssumptionCache.cpp @@ -172,7 +172,7 @@ void AssumptionCache::scanFunction() { for (BasicBlock &B : F) for (Instruction &I : B) if (isa(&I)) - AssumeHandles.push_back({&I, ExprResultIdx}); + AssumeHandles.push_back(&I); // Mark the scan as complete. Scanned = true; @@ -188,7 +188,7 @@ void AssumptionCache::registerAssumption(AssumeInst *CI) { if (!Scanned) return; - AssumeHandles.push_back({CI, ExprResultIdx}); + AssumeHandles.push_back(CI); #ifndef NDEBUG assert(CI->getParent() && diff --git a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp index c2e58ba393553..149b6f6f5b5ed 100644 --- a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp +++ b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp @@ -21,8 +21,8 @@ DropUnnecessaryAssumesPass::run(Function &F, FunctionAnalysisManager &FAM) { AssumptionCache &AC = FAM.getResult(F); bool Changed = false; - for (AssumptionCache::ResultElem &Elem : AC.assumptions()) { - auto *Assume = cast_or_null(Elem.Assume); + for (WeakVH &Elem : AC.assumptions()) { + auto *Assume = cast_or_null(Elem); if (!Assume) continue; From e6e90412fd1e0d4297f4849d79de744c396ebd69 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 24 Sep 2025 11:22:23 +0200 Subject: [PATCH 2/2] add const --- llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp index 149b6f6f5b5ed..8b3bd50a7e53f 100644 --- a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp +++ b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp @@ -21,7 +21,7 @@ DropUnnecessaryAssumesPass::run(Function &F, FunctionAnalysisManager &FAM) { AssumptionCache &AC = FAM.getResult(F); bool Changed = false; - for (WeakVH &Elem : AC.assumptions()) { + for (const WeakVH &Elem : AC.assumptions()) { auto *Assume = cast_or_null(Elem); if (!Assume) continue;