[llvm] [DropUnnecessaryAssumes] Add support for operand bundles (PR #160311)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 10:03:19 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.empty()) {
+ // 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));
----------------
andjo403 wrote:
why is there a need to register the assumption? If I understand it correct is the AssumptionAnalysis not preserved. or if it is preserved shall unregisterAssumption be called for the old assumption?
https://github.com/llvm/llvm-project/pull/160311
More information about the llvm-commits
mailing list