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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 05:21:12 PDT 2025


================
@@ -26,26 +36,64 @@ DropUnnecessaryAssumesPass::run(Function &F, FunctionAnalysisManager &FAM) {
     if (!Assume)
       continue;
 
-    // TODO: Handle assumes with operand bundles.
-    if (Assume->hasOperandBundles())
+    if (Assume->hasOperandBundles()) {
+      // Handle operand bundle assumptions.
+      SmallVector<WeakTrackingVH> DeadBundleArgs;
+      SmallVector<OperandBundleDef> KeptBundles;
+      unsigned NumBundles = Assume->getNumOperandBundles();
+      for (unsigned I = 0; I != NumBundles; ++I) {
+        auto IsDead = [](OperandBundleUse Bundle) {
+          // "ignore" operand bundles are always dead.
+          if (Bundle.getTagName() == "ignore")
+            return true;
+
+          // Bundles without arguments do not affect any specific values.
+          // Always keep them for now.
+          if (Bundle.Inputs.empty())
+            return false;
+
+          SmallVector<Value *> Affected;
+          AssumptionCache::findValuesAffectedByOperandBundle(
+              Bundle, [&](Value *A) { Affected.push_back(A); });
+
+          return affectedValuesAreEphemeral(Affected);
+        };
+
+        OperandBundleUse Bundle = Assume->getOperandBundleAt(I);
+        if (IsDead(Bundle))
+          append_range(DeadBundleArgs, Bundle.Inputs);
+        else
+          KeptBundles.emplace_back(Bundle);
+      }
+
+      if (KeptBundles.size() != NumBundles) {
+        if (KeptBundles.size() == 0) {
----------------
artagnon wrote:

```suggestion
        if (KeptBundles.empty()) {
```

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


More information about the llvm-commits mailing list