[llvm] [SLP] Gather operands of associative binary chains into one node (PR #208514)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 11:51:12 PDT 2026


================
@@ -12655,6 +12970,48 @@ void BoUpSLP::buildTreeRec(ArrayRef<Value *> VLRef, unsigned Depth,
   }
   InstructionsCompatibilityAnalysis Analysis(*DT, *DL, *TTI, *TLI);
   SmallVector<ValueList> Operands = Analysis.buildOperands(S, VL);
+  // Flatten associative binary chains into operand columns. Only the peeled
+  // chain links are required to be single-use (they are erased); the root
+  // being flattened may have other uses. Skip alt-shuffle, copyable, and
+  // non-associative nodes. Restricted to BinaryOperator: isAssociative() is
+  // also true for associative intrinsics (e.g. smax/smin/umax/umin), which are
+  // CallInst, not BinaryOperator, and are not supported by the
+  // copyable-identity machinery used below (ConstantExpr::getBinOpIdentity,
+  // isSupportedOpcode).
----------------
bababuck wrote:

```suggestion
  // isSupportedOpcode. isReassocIdentityConstant).
```

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


More information about the llvm-commits mailing list