[llvm] [VPlan] Simplify VPPhi with all-eq incoming (PR #190059)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 10:17:48 PDT 2026


================
@@ -1645,15 +1645,14 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
     return;
   }
 
-  if (isa<VPPhi, VPWidenPHIRecipe, VPHeaderPHIRecipe>(Def)) {
-    if (Def->getNumOperands() == 1) {
-      Def->replaceAllUsesWith(Def->getOperand(0));
-      return;
-    }
-    if (auto *Phi = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(Def)) {
-      if (all_equal(Phi->incoming_values()))
-        Phi->replaceAllUsesWith(Phi->getOperand(0));
-    }
+  if (auto *Phi = dyn_cast<VPPhiAccessors>(Def)) {
+    // TODO: We cannot simplify all phis with all-eq incoming yet due to various
+    // incomplete phi constructions.
+    if ((isa<VPPhi, VPFirstOrderRecurrencePHIRecipe>(Def) &&
+         all_equal(Phi->incoming_values())) ||
+        (isa<VPWidenPHIRecipe, VPHeaderPHIRecipe>(Def) &&
+         Def->getNumOperands() == 1))
+      Def->replaceAllUsesWith(Phi->getIncomingValue(0));
----------------
eas wrote:

```suggestion
    if (!all_equal(Phi->incoming_values())
      return;
 
    // TODO: We cannot simplify all phis with all-eq incoming yet due to various
    // incomplete phi constructions.
    if (isa<VPWidenPHIRecipe, VPHeaderPHIRecipe>(Def) &&
         Def->getNumOperands() != 1)
       return;
    if (!isa<VPPhi, VPFirstOrderRecurrencePHIRecipe, VPWidenPHIRecipe, VPHeaderPHIRecipe>(Def))
      return;
      
    Def->replaceAllUsesWith(Phi->getIncomingValue(0));
```

to separate desired logic from workarounds?

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


More information about the llvm-commits mailing list