[llvm] [AssumptionCache] Don't use ResultElem for assumption list (NFC) (PR #160462)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 01:21:32 PDT 2025
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/160462
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.
>From b614ead3900d6d584ba7eff3f8eccebba24aec93 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 24 Sep 2025 10:18:08 +0200
Subject: [PATCH] [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<ResultElem, 4> AssumeHandles;
+ SmallVector<WeakVH, 4> AssumeHandles;
class LLVM_ABI AffectedValueCallbackVH final : public CallbackVH {
AssumptionCache *AC;
@@ -148,7 +148,7 @@ class AssumptionCache {
/// FIXME: We should replace this with pointee_iterator<filter_iterator<...>>
/// when we can write that to filter out the null values. Then caller code
/// will become simpler.
- MutableArrayRef<ResultElem> assumptions() {
+ MutableArrayRef<WeakVH> 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<AssumeInst>(&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<AssumptionAnalysis>(F);
bool Changed = false;
- for (AssumptionCache::ResultElem &Elem : AC.assumptions()) {
- auto *Assume = cast_or_null<AssumeInst>(Elem.Assume);
+ for (WeakVH &Elem : AC.assumptions()) {
+ auto *Assume = cast_or_null<AssumeInst>(Elem);
if (!Assume)
continue;
More information about the llvm-commits
mailing list