[llvm] [VPlan] Merge `fcmp uno` feeding AnyOf. (PR #166823)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 16 08:40:28 PST 2025


================
@@ -1220,6 +1220,37 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
     }
   }
 
+  // Fold any-of (fcmp uno %A, %A), (fcmp uno %B, %B), ... ->
+  //      any-of (fcmp uno %A, %B), ...
+  if (match(Def, m_AnyOf())) {
+    SmallVector<VPValue *, 4> NewOps;
+    VPRecipeBase *UnpairedCmp = nullptr;
+    for (VPValue *Op : Def->operands()) {
+      VPValue *X;
+      if (Op->getNumUsers() > 1 ||
+          !match(Op, m_SpecificCmp(CmpInst::FCMP_UNO, m_VPValue(X),
+                                   m_Deferred(X)))) {
+        NewOps.push_back(Op);
+        continue;
+      }
+      if (UnpairedCmp) {
+        NewOps.push_back(Builder.createFCmp(CmpInst::FCMP_UNO,
+                                            UnpairedCmp->getOperand(0), X));
+        UnpairedCmp = nullptr;
+      } else {
+        UnpairedCmp = Op->getDefiningRecipe();
----------------
ayalz wrote:

nit: clearer for first alternative to be w/o early continue and second alternative to be the simpler !UnpairedCmp case which at runtime precedes the (third) UnpairedCmp case?
```suggestion
      } else if (!UnpairedCmp) {
        UnpairedCmp = Op->getDefiningRecipe();
      } else {
        NewOps.push_back(Builder.createFCmp(CmpInst::FCMP_UNO,
                                            UnpairedCmp->getOperand(0), X));
        UnpairedCmp = nullptr;
      }
```

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


More information about the llvm-commits mailing list