[llvm] 5f928a2 - [SLP]Properly define incoming block for user PHI nodes.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 08:01:54 PST 2023
Author: Alexey Bataev
Date: 2023-02-21T08:01:24-08:00
New Revision: 5f928a223ef2c14701eab3077a534c1e49269a51
URL: https://github.com/llvm/llvm-project/commit/5f928a223ef2c14701eab3077a534c1e49269a51
DIFF: https://github.com/llvm/llvm-project/commit/5f928a223ef2c14701eab3077a534c1e49269a51.diff
LOG: [SLP]Properly define incoming block for user PHI nodes.
MainOp of the PHI vectorizable entries contains the proper order of
incoming blocks, not the last instruction in the block.
Added:
llvm/test/Transforms/SLPVectorizer/phi-not-ordered.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 3ff40b5c9247e..b0c0c5ff0d2da 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8260,10 +8260,16 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
// reused elements too for better cost estimation.
Instruction &UserInst =
getLastInstructionInBundle(TE->UserTreeIndices.front().UserTE);
- auto *PHI = dyn_cast<PHINode>(&UserInst);
- auto *NodeUI = DT->getNode(
- PHI ? PHI->getIncomingBlock(TE->UserTreeIndices.front().EdgeIdx)
- : UserInst.getParent());
+ BasicBlock *ParentBB = nullptr;
+ // Main node of PHI entries keeps the correct order of operands/incoming
+ // blocks.
+ if (auto *PHI =
+ dyn_cast<PHINode>(TE->UserTreeIndices.front().UserTE->getMainOp())) {
+ ParentBB = PHI->getIncomingBlock(TE->UserTreeIndices.front().EdgeIdx);
+ } else {
+ ParentBB = UserInst.getParent();
+ }
+ auto *NodeUI = DT->getNode(ParentBB);
assert(NodeUI && "Should only process reachable instructions");
SmallPtrSet<Value *, 4> GatheredScalars(VL.begin(), VL.end());
auto CheckOrdering = [&](Instruction *LastEI) {
diff --git a/llvm/test/Transforms/SLPVectorizer/phi-not-ordered.ll b/llvm/test/Transforms/SLPVectorizer/phi-not-ordered.ll
new file mode 100644
index 0000000000000..9ccadf69c26be
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/phi-not-ordered.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=slp-vectorizer -S < %s | FileCheck %s
+
+define void @f(i16 %0) {
+; CHECK-LABEL: @f(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[FOR_COND:%.*]]
+; CHECK: for.cond:
+; CHECK-NEXT: [[TMP1:%.*]] = phi i16 [ 0, [[FOR_END5:%.*]] ], [ [[TMP0:%.*]], [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[B_0:%.*]] = phi i16 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[FOR_END5]] ]
+; CHECK-NEXT: [[INC]] = add i16 0, 0
+; CHECK-NEXT: br label [[FOR_BODY2:%.*]]
+; CHECK: for.body2:
+; CHECK-NEXT: br label [[FOR_BODY2]]
+; CHECK: for.end5:
+; CHECK-NEXT: br label [[FOR_COND]]
+;
+entry:
+ br label %for.cond
+
+for.cond:
+ %1 = phi i16 [ 0, %for.end5 ], [ %0, %entry ]
+ %b.0 = phi i16 [ 0, %entry ], [ %inc, %for.end5 ]
+ %inc = add i16 0, 0
+ br label %for.body2
+
+for.body2:
+ br label %for.body2
+
+for.end5:
+ br label %for.cond
+}
More information about the llvm-commits
mailing list