[llvm] [DropUnnecessaryAssumes] Make the ephemeral value check more precise (PR #160700)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 03:08:19 PDT 2025


================
@@ -17,13 +18,44 @@ using namespace llvm;
 using namespace llvm::PatternMatch;
 
 static bool affectedValuesAreEphemeral(ArrayRef<Value *> Affected) {
-  // If all the affected uses have only one use (part of the assume), then
-  // the assume does not provide useful information. Note that additional
-  // users may appear as a result of inlining and CSE, so we should only
-  // make this assumption late in the optimization pipeline.
-  // TODO: Handle dead cyclic usages.
-  // TODO: Handle multiple dead assumes on the same value.
-  return all_of(Affected, match_fn(m_OneUse(m_Value())));
+  // Check whether all the uses are ephemeral, i.e. recursively only used
+  // by assumes. In that case, the assume does not provide useful information.
+  // Note that additional users may appear as a result of inlining and CSE,
+  // so we should only make this assumption late in the optimization pipeline.
+  SmallSetVector<User *, 16> Worklist;
----------------
nikic wrote:

Done. Though it's worth noting that for SmallSetVector the template argument doesn't control just the small size, but also the amount of elements for which linear scan set is used, so increasing this value is not always profitable (though 32 is considered acceptable still).

https://github.com/llvm/llvm-project/pull/160700


More information about the llvm-commits mailing list