[llvm] [SLP]Initial support for copyable elements (non-schedulable only) (PR #140279)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 10:25:20 PDT 2025


================
@@ -1220,6 +1235,48 @@ class InstructionsState {
   InstructionsState(Instruction *MainOp, Instruction *AltOp)
       : MainOp(MainOp), AltOp(AltOp) {}
   static InstructionsState invalid() { return {nullptr, nullptr}; }
+
+  bool isCopyableElement(Value *V) const {
+    assert(valid() && "InstructionsState is invalid.");
+    if (isAltShuffle() || getOpcode() == Instruction::GetElementPtr)
+      return false;
+    auto *I = dyn_cast<Instruction>(V);
+    if (!I && isa<PoisonValue>(V))
+      return false;
+    // FIXME: remove doesNotNeedToBeScheduled() and isa<PHINode>() check once
+    // scheduling is supported.
+    return !I ||
+           (I->getParent() != MainOp->getParent() &&
+            (!isVectorLikeInstWithConstOps(I) ||
+             !isVectorLikeInstWithConstOps(MainOp))) ||
+           (I->getOpcode() != MainOp->getOpcode() &&
+            (isa<PHINode>(I) || doesNotNeedToBeScheduled(I)) &&
+            (!I->isBinaryOp() || getMatchingMainOpOrAltOp(I) != MainOp));
+  }
+
+  bool areInstructionsWithCopyableElements(ArrayRef<Value *> VL) const {
+    assert(valid() && "InstructionsState is invalid.");
+    bool HasAtLeastOneCopyableElement = false;
+    auto IsCopyableElement = [&](Value *V) {
+      bool IsCopyable = isCopyableElement(V);
+      HasAtLeastOneCopyableElement |= IsCopyable;
+      return IsCopyable;
+    };
+    return !isAltShuffle() && all_of(VL, [&](Value *V) {
----------------
alexey-bataev wrote:

Done

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


More information about the llvm-commits mailing list