[llvm] [SLP] Normalize copyable operand order via majority voting (PR #191631)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 08:04:31 PDT 2026


================
@@ -11931,12 +11931,76 @@ class InstructionsCompatibilityAnalysis {
     if (S.areInstructionsWithCopyableElements()) {
       MainOp = S.getMainOp();
       MainOpcode = S.getOpcode();
+      const bool IsCommutative =
+          isCommutative(MainOp) && MainOp->getNumOperands() == 2;
       Operands.assign(MainOp->getNumOperands(),
                       BoUpSLP::ValueList(VL.size(), nullptr));
+      // Build operands and simultaneously count (ID0, ID1) pair
+      // frequencies for commutative operand normalization. Pairs and
+      // their inverses are tracked under a canonical key so that
+      // (Load, Add) and (Add, Load) contribute to the same bucket.
+      struct PairInfo {
+        unsigned FwdCount = 0;
+        unsigned RevCount = 0;
----------------
alexey-bataev wrote:

We do. Otherwise may have non-deterministic results.

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


More information about the llvm-commits mailing list