[llvm] 7db87a6 - [SLP]Fix PR66795: Check correct deps for vectorized inst with multiple

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 12:11:52 PDT 2023


Author: Alexey Bataev
Date: 2023-09-19T12:11:33-07:00
New Revision: 7db87a66b0206af027724fc1704e5e5ce7772a45

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

LOG: [SLP]Fix PR66795: Check correct deps for vectorized inst with multiple
vectorized node uses.

If the instruction is vectorized in many different vector nodes, it may
break the dependency analysis for gathered nodes with matched scalars.
Need to properly check the dependency between such gather nodes to avoid
cycle dependency.

Added: 
    llvm/test/Transforms/SLPVectorizer/X86/multi-node-vectorized-insts.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 6c5d83472da4496..38ef4fa9464ffb7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8939,6 +8939,12 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
             TE->UserTreeIndices.front().EdgeIdx <
                 TEPtr->UserTreeIndices.front().EdgeIdx)
           continue;
+        // If the user instruction is used for some reason in 
diff erent
+        // vectorized nodes - make it depend on index.
+        if (TE->UserTreeIndices.front().UserTE !=
+                TEPtr->UserTreeIndices.front().UserTE &&
+            TE->Idx > TEPtr->Idx)
+          continue;
       }
       // Check if the user node of the TE comes after user node of EntryPtr,
       // otherwise EntryPtr depends on TE.

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/multi-node-vectorized-insts.ll b/llvm/test/Transforms/SLPVectorizer/X86/multi-node-vectorized-insts.ll
new file mode 100644
index 000000000000000..ea51995383ae6cc
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/multi-node-vectorized-insts.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define void @test(double %0) {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: double [[TMP0:%.*]]) {
+; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> poison, double [[TMP0]], i32 0
+; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    br label [[TMP4:%.*]]
+; CHECK:       4:
+; CHECK-NEXT:    [[TMP5:%.*]] = fsub <2 x double> zeroinitializer, [[TMP3]]
+; CHECK-NEXT:    [[TMP6:%.*]] = fsub <2 x double> zeroinitializer, [[TMP3]]
+; CHECK-NEXT:    br label [[DOTBACKEDGE:%.*]]
+; CHECK:       .backedge:
+; CHECK-NEXT:    [[TMP7:%.*]] = fmul <2 x double> [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    [[TMP8:%.*]] = fcmp olt <2 x double> [[TMP7]], zeroinitializer
+; CHECK-NEXT:    br label [[TMP4]]
+;
+  br label %2
+
+2:
+  %3 = fsub double 0.000000e+00, %0
+  %4 = fsub double 0.000000e+00, %0
+  %5 = fsub double 0.000000e+00, %0
+  br label %.backedge
+
+.backedge:
+  %6 = fmul double %4, %5
+  %7 = fcmp olt double %6, 0.000000e+00
+  %8 = fmul double %5, %3
+  %9 = fcmp olt double %8, 0.000000e+00
+  br label %2
+}


        


More information about the llvm-commits mailing list