[clang] [LifetimeSafety][NFC] Do not store empty loan sets (PR #246460)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 09:56:02 PST 2026
https://github.com/Xazax-hun updated https://github.com/llvm/llvm-project/pull/246460
>From e3319d9c52d44b97f51036e1c0e7d861a002b2f0 Mon Sep 17 00:00:00 2001
From: Gabor Horvath <gaborh at apple.com>
Date: Thu, 26 Nov 2026 17:31:05 +0000
Subject: [PATCH 1/2] [LifetimeSafety][NFC] Do not store empty loan sets
An origin missing from the loan propagation lattice has no loans, so
remove it instead of storing an empty set when it is killed, expires or
receives no loans from a flow. This keeps the maps smaller.
On the lifetime safety benchmarks this reduces the peak memory by 8% for
the CFG merge test and 3% for the switch fan-out test, with no change in
instructions for the others.
Assisted-by: Claude Opus 5.5
---
.../lib/Analysis/LifetimeSafety/LoanPropagation.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
index aa26711b6b78b8..646eb6ef8a1c46 100644
--- a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
@@ -283,11 +283,13 @@ class AnalysisImpl
}
Lattice setLoans(Lattice L, OriginID OID, LoanSet Loans) {
- if (isPersistent(OID))
- return Lattice(OriginLoanMapFactory.add(L.PersistentOrigins, OID, Loans),
- L.BlockLocalOrigins);
- return Lattice(L.PersistentOrigins,
- OriginLoanMapFactory.add(L.BlockLocalOrigins, OID, Loans));
+ OriginLoanMap &Map =
+ isPersistent(OID) ? L.PersistentOrigins : L.BlockLocalOrigins;
+ // An origin that is not in the map has no loans, so do not store empty
+ // sets.
+ Map = Loans.isEmpty() ? OriginLoanMapFactory.remove(Map, OID)
+ : OriginLoanMapFactory.add(Map, OID, Loans);
+ return L;
}
LoanSet getLoans(Lattice L, OriginID OID) const {
>From 529e3ceb286e6fc592db17a47b8916662720c8ff Mon Sep 17 00:00:00 2001
From: Gabor Horvath <gaborh at apple.com>
Date: Thu, 26 Nov 2026 17:55:44 +0000
Subject: [PATCH 2/2] [LifetimeSafety][NFC] Address review comments
Assisted-by: Claude Opus 5.5
---
clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
index 646eb6ef8a1c46..58979bbcfd5cee 100644
--- a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
@@ -285,8 +285,7 @@ class AnalysisImpl
Lattice setLoans(Lattice L, OriginID OID, LoanSet Loans) {
OriginLoanMap &Map =
isPersistent(OID) ? L.PersistentOrigins : L.BlockLocalOrigins;
- // An origin that is not in the map has no loans, so do not store empty
- // sets.
+ // An origin that is not in the map has no loans, so do not store those.
Map = Loans.isEmpty() ? OriginLoanMapFactory.remove(Map, OID)
: OriginLoanMapFactory.add(Map, OID, Loans);
return L;
More information about the cfe-commits
mailing list