[llvm] [SLP] Make getSameOpcode support different instructions if they have same semantics. (PR #112181)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 17:39:12 PDT 2024


================
@@ -2335,24 +2479,41 @@ class BoUpSLP {
                                  : cast<Instruction>(VL[0])->getNumOperands();
       OpsVec.resize(NumOperands);
       unsigned NumLanes = VL.size();
-      for (unsigned OpIdx = 0; OpIdx != NumOperands; ++OpIdx) {
+      InstructionsState S = getSameOpcode(VL, TLI);
----------------
HanKuanChen wrote:

Should we only use `VLOperands`? Right now the code is like this
```
      // Sort operands of the instructions so that each side is more likely to
      // have the same opcode.
      if (isa<BinaryOperator>(VL0) && isCommutative(VL0)) {
        ValueList Left, Right;
        reorderInputsAccordingToOpcode(VL, Left, Right, *this);
        TE->setOperand(0, Left);
        TE->setOperand(1, Right);
        buildTree_rec(Left, Depth + 1, {TE, 0});
        buildTree_rec(Right, Depth + 1, {TE, 1});
        return;
      }

      TE->setOperandsInOrder();
      for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
        buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
```
We need to implement the logics in `VLOperands` and `Tree::setOperandsInOrder`. It will be simpler if we use `VLOperands` only.

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


More information about the llvm-commits mailing list