[llvm-branch-commits] [llvm] c6b2b84 - Revert "[AssumptionCache] Limit the number of assumptions inspected per value…"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 24 05:42:11 PDT 2026
Author: Matsu
Date: 2026-08-24T05:42:07-07:00
New Revision: c6b2b84d0611dd57ac0bd69f1a05061ce860b256
URL: https://github.com/llvm/llvm-project/commit/c6b2b84d0611dd57ac0bd69f1a05061ce860b256
DIFF: https://github.com/llvm/llvm-project/commit/c6b2b84d0611dd57ac0bd69f1a05061ce860b256.diff
LOG: Revert "[AssumptionCache] Limit the number of assumptions inspected per value…"
This reverts commit 904188e382f658886ab2c37ded5e54aa72c2eadd.
Added:
Modified:
llvm/include/llvm/Analysis/AssumptionCache.h
llvm/lib/Analysis/AssumptionCache.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
Removed:
llvm/test/Analysis/AssumptionCache/max-assumes-per-value.ll
################################################################################
diff --git a/llvm/include/llvm/Analysis/AssumptionCache.h b/llvm/include/llvm/Analysis/AssumptionCache.h
index 8b07650146ba2..ed335c084fde8 100644
--- a/llvm/include/llvm/Analysis/AssumptionCache.h
+++ b/llvm/include/llvm/Analysis/AssumptionCache.h
@@ -34,9 +34,6 @@ class raw_ostream;
class TargetTransformInfo;
class Value;
-/// Set by -max-assumes-per-value; see AssumptionCache::assumptionsFor().
-LLVM_ABI extern unsigned MaxAssumesPerValue;
-
/// A cache of \@llvm.assume calls within a function.
///
/// This cache provides fast lookup of assumptions within a function by caching
@@ -166,19 +163,7 @@ class AssumptionCache {
}
/// Access the list of assumptions which affect this value.
- ///
- /// Callers inspect every assumption returned, so this returns only the first
- /// -max-assumes-per-value of them.
MutableArrayRef<ResultElem> assumptionsFor(const Value *V) {
- return allAssumptionsFor(V).take_front(MaxAssumesPerValue);
- }
-
- /// Access the list of assumptions which affect this value, ignoring the
- /// -max-assumes-per-value limit.
- ///
- /// Only for callers which must observe every assumption, such as cache
- /// verification. Analyses should use assumptionsFor().
- MutableArrayRef<ResultElem> allAssumptionsFor(const Value *V) {
if (!Scanned)
scanFunction();
diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index 555bc266c8d46..87e63e95a46d6 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -34,7 +34,6 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
-#include <limits>
using namespace llvm;
using namespace llvm::PatternMatch;
@@ -44,14 +43,6 @@ static cl::opt<bool>
cl::desc("Enable verification of assumption cache"),
cl::init(false));
-unsigned llvm::MaxAssumesPerValue = 1024;
-
-static cl::opt<unsigned, true> MaxAssumesPerValueOpt(
- "max-assumes-per-value", cl::Hidden, cl::location(MaxAssumesPerValue),
- cl::init(1024),
- cl::desc("Maximum number of assumptions affecting a single value that "
- "analyses will inspect"));
-
SmallVector<AssumptionCache::ResultElem, 1> &
AssumptionCache::getOrInsertAffectedValues(Value *V) {
// Try using find_as first to avoid creating extra value handles just for the
@@ -218,27 +209,6 @@ void AssumptionCache::scanFunction() {
updateAffectedValues(cast<AssumeInst>(A));
}
-/// Check the assumptions cached for \p F, collecting them in \p Cached. Returns
-/// a description of the first invariant violated, or nullptr if there is none.
-static const char *
-findCacheViolation(const Function &F, ArrayRef<WeakVH> Assumptions,
- SmallPtrSetImpl<const CallInst *> &Cached) {
- for (const WeakVH &VH : Assumptions) {
- if (!VH)
- continue;
-
- const auto *CI = cast<CallInst>(VH);
- if (CI->getFunction() != &F)
- return "Cached assumption not inside this function";
- if (!match(CI, m_Intrinsic<Intrinsic::assume>()))
- return "Cached something other than a call to @llvm.assume";
- if (!Cached.insert(CI).second)
- return "Cache contains multiple copies of a call";
- }
-
- return nullptr;
-}
-
void AssumptionCache::registerAssumption(AssumeInst *CI) {
// If we haven't scanned the function yet, just drop this assumption. It will
// be found when we scan later.
@@ -255,19 +225,18 @@ void AssumptionCache::registerAssumption(AssumeInst *CI) {
// We expect the number of assumptions to be small, so in an asserts build
// check that we don't accumulate duplicates and that all assumptions point
- // to the same function. Scanning the whole cache on every registration is
- // quadratic, so stop once it outgrows that expectation unless expensive
- // checks are enabled. Larger caches are checked by
- // AssumptionCacheTracker::verifyAnalysis() instead.
-#ifdef EXPENSIVE_CHECKS
- constexpr unsigned MaxAssumesToVerify = std::numeric_limits<unsigned>::max();
-#else
- constexpr unsigned MaxAssumesToVerify = 64;
-#endif
- if (AssumeHandles.size() <= MaxAssumesToVerify) {
- SmallPtrSet<const CallInst *, 16> Cached;
- if (const char *Violation = findCacheViolation(F, AssumeHandles, Cached))
- llvm_unreachable(Violation);
+ // to the same function.
+ SmallPtrSet<Value *, 16> AssumptionSet;
+ for (auto &VH : AssumeHandles) {
+ if (!VH)
+ continue;
+
+ assert(&F == cast<Instruction>(VH)->getParent()->getParent() &&
+ "Cached assumption not inside this function!");
+ assert(match(cast<CallInst>(VH), m_Intrinsic<Intrinsic::assume>()) &&
+ "Cached something other than a call to @llvm.assume!");
+ assert(AssumptionSet.insert(VH).second &&
+ "Cache contains multiple copies of a call!");
}
#endif
@@ -355,18 +324,16 @@ void AssumptionCacheTracker::verifyAnalysis() const {
if (!VerifyAssumptionCache)
return;
+ SmallPtrSet<const CallInst *, 4> AssumptionSet;
for (const auto &I : AssumptionCaches) {
- const Function &F = cast<Function>(*I.first);
-
- SmallPtrSet<const CallInst *, 4> Cached;
- if (const char *Violation =
- findCacheViolation(F, I.second->assumptions(), Cached))
- report_fatal_error(Violation);
+ for (auto &VH : I.second->assumptions())
+ if (VH)
+ AssumptionSet.insert(cast<CallInst>(VH));
- for (const BasicBlock &B : F)
+ for (const BasicBlock &B : cast<Function>(*I.first))
for (const Instruction &II : B)
if (match(&II, m_Intrinsic<Intrinsic::assume>()) &&
- !Cached.count(cast<CallInst>(&II)))
+ !AssumptionSet.count(cast<CallInst>(&II)))
report_fatal_error("Assumption in scanned function not in cache");
}
}
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 2c7418cb98f84..eb5a6d1b4ef97 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -2148,7 +2148,7 @@ bool CodeExtractor::verifyAssumptionCache(const Function &OldFunc,
// There shouldn't be any stale affected values in the assumption cache
// that were previously in the old function, but that have now been moved
// to the new function.
- for (auto AffectedValVH : AC->allAssumptionsFor(I->getOperand(0))) {
+ for (auto AffectedValVH : AC->assumptionsFor(I->getOperand(0))) {
auto *AffectedCI = dyn_cast_or_null<CallInst>(AffectedValVH);
if (!AffectedCI)
continue;
diff --git a/llvm/test/Analysis/AssumptionCache/max-assumes-per-value.ll b/llvm/test/Analysis/AssumptionCache/max-assumes-per-value.ll
deleted file mode 100644
index 773bd056c2db6..0000000000000
--- a/llvm/test/Analysis/AssumptionCache/max-assumes-per-value.ll
+++ /dev/null
@@ -1,37 +0,0 @@
-; RUN: opt < %s -S -passes=instsimplify -max-assumes-per-value=3 | FileCheck %s --check-prefixes=CHECK,USED
-; RUN: opt < %s -S -passes=instsimplify -max-assumes-per-value=2 | FileCheck %s --check-prefixes=CHECK,IGNORED
-
-; Analyses inspect every assumption returned for a value, so only the first
-; -max-assumes-per-value assumptions affecting it are used. Here the assumption
-; that proves the comparison is the third one.
-
-declare void @llvm.assume(i1)
-
-define i1 @assumes_within_limit(i32 %x) {
-; CHECK-LABEL: define i1 @assumes_within_limit(
-; USED: ret i1 true
-; IGNORED: ret i1 %cmp
- %u1 = icmp ne i32 %x, 1234
- call void @llvm.assume(i1 %u1)
- %u2 = icmp ne i32 %x, 5678
- call void @llvm.assume(i1 %u2)
- %c = icmp sgt i32 %x, 41
- call void @llvm.assume(i1 %c)
- %cmp = icmp sgt i32 %x, 0
- ret i1 %cmp
-}
-
-; The limit applies per value, so assumptions about %y are still used when %x is
-; affected by more of them than the limit allows.
-define i1 @limit_is_per_value(i32 %x, i32 %y) {
-; CHECK-LABEL: define i1 @limit_is_per_value(
-; CHECK: ret i1 true
- %cx = icmp sgt i32 %x, 41
- call void @llvm.assume(i1 %cx)
- call void @llvm.assume(i1 %cx)
- call void @llvm.assume(i1 %cx)
- %cy = icmp sgt i32 %y, 41
- call void @llvm.assume(i1 %cy)
- %cmp = icmp sgt i32 %y, 0
- ret i1 %cmp
-}
More information about the llvm-branch-commits
mailing list