[llvm] [DropUnnecessaryAssumes] Add support for operand bundles (PR #160311)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 12:08:28 PDT 2025


================
@@ -26,8 +37,41 @@ DropUnnecessaryAssumesPass::run(Function &F, FunctionAnalysisManager &FAM) {
     if (!Assume)
       continue;
 
-    // TODO: Handle assumes with operand bundles.
-    if (Assume->hasOperandBundles())
+    SmallVector<WeakTrackingVH> DeadBundleArgs;
+    SmallVector<OperandBundleDef> KeptBundles;
+    unsigned NumBundles = Assume->getNumOperandBundles();
+    for (unsigned I = 0; I != NumBundles; ++I) {
+      // Handle operand bundle assumptions.
+      OperandBundleUse Bundle = Assume->getOperandBundleAt(I);
+      SmallPtrSet<Value *, 8> Affected;
+      AssumptionCache::findValuesAffectedByOperandBundle(
+          Bundle, [&](Value *A) { Affected.insert(A); });
+
+      if (affectedValuesAreEphemeral(Affected))
+        append_range(DeadBundleArgs, Bundle.Inputs);
+      else
+        KeptBundles.emplace_back(Bundle);
+    }
+
+    if (KeptBundles.size() != NumBundles) {
+      if (KeptBundles.size() == 0) {
----------------
artagnon wrote:

This seems to be a serious thinko: how can we unconditionally remove the assume if the assume-condition isn't dead?

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


More information about the llvm-commits mailing list