[llvm] [SLP]Model copyable lanes of idempotent binops as op(V, V) when the operand column has a constant lane (PR #220252)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 21:28:23 PDT 2026


================
@@ -11021,6 +11032,59 @@ class InstructionsCompatibilityAnalysis {
     return {V, selectBestIdempotentValue()};
   }
 
+  /// Returns the copyable lanes of an idempotent binop to be modeled as
+  /// op(V, V) == V instead of op(V, identity): when the operand column the
+  /// lane joins also holds a constant lane, the reorder would align that
+  /// column as constants and move the lane out, breaking the opcode-peer
+  /// node, while the symmetric form is reorder-proof. The other column must
+  /// be an instruction node so the lane is absorbed there as a copyable
+  /// rather than breaking a constant column.
+  SmallVector<const Value *> findSelfOpLanes(const InstructionsState &S,
+                                             ArrayRef<Value *> VL,
+                                             const BoUpSLP &R) const {
+    SmallVector<const Value *> SelfOpLanes;
+    if (!Instruction::isIdempotent(MainOpcode) || none_of(VL, [&](Value *V) {
+          if (isa<PoisonValue>(V))
+            return false;
+          if (S.isCopyableElement(V))
+            return isa<Constant>(V);
+          return isa<Constant>(cast<Instruction>(V)->getOperand(0));
+        }))
----------------
bababuck wrote:

```suggestion
    if (!Instruction::isIdempotent(MainOpcode) || !S. areInstructionsWithCopyableElements() || none_of(VL, [&](Value *V) {
          if (isa<PoisonValue>(V))
            return false;
          if (S.isCopyableElement(V))
            return isa<Constant>(V);
          return isa<Constant>(cast<Instruction>(V)->getOperand(0));
        }))
```

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


More information about the llvm-commits mailing list