Skip to content

Commit c80b503

Browse files
author
Valery Dmitriev
authored
[SLP] Improve gather tree nodes matching when users are PHIs. (#69392)
1 parent e3ae2a5 commit c80b503

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9043,6 +9043,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
90439043
// blocks.
90449044
if (auto *PHI = dyn_cast<PHINode>(TEUseEI.UserTE->getMainOp())) {
90459045
TEInsertBlock = PHI->getIncomingBlock(TEUseEI.EdgeIdx);
9046+
TEInsertPt = TEInsertBlock->getTerminator();
90469047
} else {
90479048
TEInsertBlock = TEInsertPt->getParent();
90489049
}
@@ -9106,9 +9107,10 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
91069107
const Instruction *InsertPt =
91079108
UserPHI ? UserPHI->getIncomingBlock(UseEI.EdgeIdx)->getTerminator()
91089109
: &getLastInstructionInBundle(UseEI.UserTE);
9109-
if (!UserPHI && TEInsertPt == InsertPt) {
9110-
// If 2 gathers are operands of the same non-PHI entry,
9111-
// compare operands indices, use the earlier one as the base.
9110+
if (TEInsertPt == InsertPt) {
9111+
// If 2 gathers are operands of the same entry (regardless of wether
9112+
// user is PHI or else), compare operands indices, use the earlier one
9113+
// as the base.
91129114
if (TEUseEI.UserTE == UseEI.UserTE && TEUseEI.EdgeIdx < UseEI.EdgeIdx)
91139115
continue;
91149116
// If the user instruction is used for some reason in different

llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
; YAML: Function: test
99
; YAML: Args:
1010
; YAML: - String: 'Stores SLP vectorized with cost '
11-
; YAML: - Cost: '-3'
11+
; YAML: - Cost: '-6'
1212
; YAML: - String: ' and with tree size '
1313
; YAML: - TreeSize: '14'
1414
; YAML: ...

0 commit comments

Comments
 (0)