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

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 11:42:15 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) {
+        // All operand bundles are dead, remove the whole assume.
+        Assume->eraseFromParent();
+      } else {
+        // Otherwise only drop the dead operand bundles.
+        CallBase *NewAssume =
+            CallBase::Create(Assume, KeptBundles, Assume->getIterator());
+        AC.registerAssumption(cast<AssumeInst>(NewAssume));
+        Assume->eraseFromParent();
+      }
+
+      RecursivelyDeleteTriviallyDeadInstructionsPermissive(DeadBundleArgs);
+      Changed = true;
+      continue;
+    }
+
+    // Ignore condition on assumes with operand bundles.
+    if (NumBundles != 0)
----------------
andjo403 wrote:

shall there be a TODO to maybe remove the condition if there still is bundles but the condition is dead?

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


More information about the llvm-commits mailing list