[llvm] ca654ac - [SLP]Fix PR79321: SLPVectorizer's PHICompare doesn't provide a strict
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 09:39:08 PST 2024
Author: Alexey Bataev
Date: 2024-01-24T09:36:25-08:00
New Revision: ca654acc16c43191228eadfec8f7241dca10b0c3
URL: https://github.com/llvm/llvm-project/commit/ca654acc16c43191228eadfec8f7241dca10b0c3
DIFF: https://github.com/llvm/llvm-project/commit/ca654acc16c43191228eadfec8f7241dca10b0c3.diff
LOG: [SLP]Fix PR79321: SLPVectorizer's PHICompare doesn't provide a strict
weak ordering.
Compared NumUses to meet the reaquirements of the strict weak ordering.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/extract-subvector-long-input.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 601d2454c1e163..5c17cd54273575 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4138,9 +4138,11 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) {
auto PHICompare = [&](unsigned I1, unsigned I2) {
Value *V1 = TE.Scalars[I1];
Value *V2 = TE.Scalars[I2];
- if (V1 == V2)
+ if (V1 == V2 || (V1->getNumUses() == 0 && V2->getNumUses() == 0))
return false;
- if (!V1->hasOneUse() || !V2->hasOneUse())
+ if (V1->getNumUses() < V2->getNumUses())
+ return true;
+ if (V1->getNumUses() > V2->getNumUses())
return false;
auto *FirstUserOfPhi1 = cast<Instruction>(*V1->user_begin());
auto *FirstUserOfPhi2 = cast<Instruction>(*V2->user_begin());
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/extract-subvector-long-input.ll b/llvm/test/Transforms/SLPVectorizer/X86/extract-subvector-long-input.ll
index 3c22804453dff0..1b54a604cd6f3a 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/extract-subvector-long-input.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/extract-subvector-long-input.ll
@@ -7,7 +7,7 @@ define void @test() {
; CHECK-NEXT: br label [[BB1:%.*]]
; CHECK: bb1:
; CHECK-NEXT: [[TMP0:%.*]] = phi <8 x i32> [ poison, [[BB10:%.*]] ], [ zeroinitializer, [[BB:%.*]] ]
-; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> poison, <2 x i32> <i32 6, i32 6>
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> poison, <2 x i32> <i32 7, i32 7>
; CHECK-NEXT: switch i32 0, label [[BB16:%.*]] [
; CHECK-NEXT: i32 0, label [[BB14:%.*]]
; CHECK-NEXT: i32 1, label [[BB11:%.*]]
More information about the llvm-commits
mailing list