[llvm] [VPlan] Make simplifyRecipe more like InstCombine (PR #212968)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 01:50:25 PDT 2026


================
@@ -1658,7 +1613,16 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) {
   for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
     for (VPRecipeBase &R : make_early_inc_range(*VPBB))
       if (auto *Def = dyn_cast<VPSingleDefRecipe>(&R))
-        simplifyRecipe(Def);
+        if (VPValue *New = simplifyRecipe(Def)) {
+          if (New != Def) {
+            // Replace the recipe with a new one.
+            Def->replaceAllUsesWith(New);
+            Def->eraseFromParent();
+          } else if (vputils::isDeadRecipe(R)) {
+            // Recipe was modified - it may be dead now.
+            Def->eraseFromParent();
+          }
----------------
lukel97 wrote:

Some simplifications can modify the recipe in place and leave the original dead, the "Try to fold Not into compares by adjusting the predicate in-place." combine is one such example. Erasing dead recipes earlier can enable more simplifications when they depend on `m_OneUse` etc. 

This is also what InstCombine does:

```c++
    if (Instruction *Result = visit(*I)) {
      ++NumCombined;
      // Should we replace the old instruction with a new one?
      if (Result != I) {
        LLVM_DEBUG(dbgs() << "IC: Old = " << *I << '\n'
                          << "    New = " << *Result << '\n');
        ...
      } else {
        LLVM_DEBUG(dbgs() << "IC: Mod = " << OrigI << '\n'
                          << "    New = " << *I << '\n');

        // If the instruction was modified, it's possible that it is now dead.
        // if so, remove it.
        if (isInstructionTriviallyDead(I, &TLI)) {
          eraseInstFromFunction(*I);
        } else {
          ...
        }
      }
```

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


More information about the llvm-commits mailing list