[llvm] [SLP]Reduce number of alternate instruction, where possible (PR #123360)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 03:46:23 PST 2025


================
@@ -3637,12 +3663,31 @@ class BoUpSLP {
                   return VL[Idx];
                 });
       InstructionsState S = getSameOpcode(Last->Scalars, *TLI);
-      if (S)
+      if (S) {
         Last->setOperations(S);
+      } else if (EntryState == TreeEntry::SplitVectorize) {
+        auto *MainOp =
+            cast<Instruction>(*find_if(Last->Scalars, IsaPred<Instruction>));
+        auto *AltOp = cast<Instruction>(*find_if(Last->Scalars, [=](Value *V) {
+          auto *I = dyn_cast<Instruction>(V);
+          return I && I->getOpcode() != MainOp->getOpcode();
+        }));
+        Last->setOperations(InstructionsState(MainOp, AltOp));
+      }
+      if (EntryState == TreeEntry::SplitVectorize) {
+        for (Value *V : VL) {
+          auto *I = dyn_cast<Instruction>(V);
+          if (!I)
+            continue;
+          ScalarsInSplitNodes.try_emplace(I, Last);
+        }
+      }
       Last->ReorderIndices.append(ReorderIndices.begin(), ReorderIndices.end());
     }
-    if (!Last->isGather()) {
+    if (!Last->isGather() && Last->State != TreeEntry::SplitVectorize) {
       for (Value *V : VL) {
+        if (isa<PoisonValue>(V))
+          continue;
----------------
RKSimon wrote:

Should this early-out have already been added or can they only be generated by earlier splits? 

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


More information about the llvm-commits mailing list