[llvm] [SLP]Treat 2-element FP reductions as always associative (PR #222715)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 04:53:44 PDT 2026


================
@@ -32744,8 +32766,11 @@ bool SLPVectorizerPass::tryToVectorize(
     case RecurKind::FAdd:
     case RecurKind::FMul: {
       FastMathFlags FMF;
-      if (auto *FPCI = dyn_cast<FPMathOperator>(Inst))
+      if (auto *FPCI = dyn_cast<FPMathOperator>(Inst)) {
         FMF = FPCI->getFastMathFlags();
+        // No need to check for associativity, if 2 reduced values.
+        FMF.setAllowReassoc(Ops.size() == 2);
----------------
MrSidims wrote:

Should it be
```
if (Ops.size() == 2)
  FMF.setAllowReassoc(true);
```

then, or we want to drop potentially presenting `reassoc` for this case?

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


More information about the llvm-commits mailing list