[llvm] eb39605 - [SLP]Do not schedule terminate copyable from main op basic block

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 30 18:05:17 PDT 2025


Author: Alexey Bataev
Date: 2025-08-30T18:05:08-07:00
New Revision: eb39605192d36806ec0d41c8c54b0817be5d80c5

URL: https://github.com/llvm/llvm-project/commit/eb39605192d36806ec0d41c8c54b0817be5d80c5
DIFF: https://github.com/llvm/llvm-project/commit/eb39605192d36806ec0d41c8c54b0817be5d80c5.diff

LOG: [SLP]Do not schedule terminate copyable from main op basic block

If the copyable instruction is a terminate instruction from the same
block, as the potential main instruction, such instruction cannot be
copyable and the value list cannot be modeled as instructions with same
(and copyables) opcodes.

Fixes #155183

Added: 
    llvm/test/Transforms/SLPVectorizer/X86/no-schedule-terminate-inst.ll

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index dad0d1e9ef555..33418d86d51df 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -10638,8 +10638,19 @@ class InstructionsCompatibilityAnalysis {
         }
       }
     }
-    if (MainOp)
+    if (MainOp) {
+      // Do not match, if any copyable is a terminator from the same block as
+      // the main operation.
+      if (any_of(VL, [&](Value *V) {
+            auto *I = dyn_cast<Instruction>(V);
+            return I && I->getParent() == MainOp->getParent() &&
+                   I->isTerminator();
+          })) {
+        MainOp = nullptr;
+        return;
+      }
       MainOpcode = MainOp->getOpcode();
+    }
   }
 
   /// Returns the idempotent value for the \p MainOp with the detected \p

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/no-schedule-terminate-inst.ll b/llvm/test/Transforms/SLPVectorizer/X86/no-schedule-terminate-inst.ll
new file mode 100644
index 0000000000000..2ae8d15a3c75d
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/no-schedule-terminate-inst.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define void @test() gc "statepoint-example" personality ptr null {
+; CHECK-LABEL: define void @test() gc "statepoint-example" personality ptr null {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:    [[INVOKE:%.*]] = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
+; CHECK-NEXT:            to label %[[BB2:.*]] unwind label %[[BB8:.*]]
+; CHECK:       [[BB2]]:
+; CHECK-NEXT:    [[ADD3:%.*]] = add i32 [[INVOKE]], 0
+; CHECK-NEXT:    br label %[[BB4:.*]]
+; CHECK:       [[BB4]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ [[ADD3]], %[[BB2]] ]
+; CHECK-NEXT:    [[PHI5:%.*]] = phi i32 [ 0, %[[BB2]] ]
+; CHECK-NEXT:    [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB2]] ]
+; CHECK-NEXT:    ret void
+; CHECK:       [[BB8]]:
+; CHECK-NEXT:    [[LANDINGPAD:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT:            cleanup
+; CHECK-NEXT:    ret void
+;
+bb:
+  %add = add i32 0, 0
+  %add1 = add i32 0, 0
+  %invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
+  to label %bb2 unwind label %bb8
+
+bb2:
+  %add3 = add i32 %invoke, 0
+  br label %bb4
+
+bb4:
+  %phi = phi i32 [ %add3, %bb2 ]
+  %phi5 = phi i32 [ 0, %bb2 ]
+  %phi6 = phi i32 [ %add, %bb2 ]
+  %phi7 = phi i32 [ %add1, %bb2 ]
+  ret void
+
+bb8:
+  %landingpad = landingpad { ptr, i32 }
+  cleanup
+  ret void
+}


        


More information about the llvm-commits mailing list