[llvm] [SLP] Improve gather tree nodes matching when users are PHIs. (PR #69392)
Valery Dmitriev via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 17 15:29:54 PDT 2023
https://github.com/valerydmit created https://github.com/llvm/llvm-project/pull/69392
None
>From f825b9efbf132e0235287d293c2c0f19684e2146 Mon Sep 17 00:00:00 2001
From: Valery N Dmitriev <valery.n.dmitriev at intel.com>
Date: Tue, 17 Oct 2023 15:10:00 -0700
Subject: [PATCH] [SLP] Improve gather tree nodes matching when users are PHIs.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 8 +++++---
.../SLPVectorizer/X86/matching-gather-nodes-phi-users.ll | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d09bf3872f04f06..0aa9754aa11958b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -9043,6 +9043,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
// blocks.
if (auto *PHI = dyn_cast<PHINode>(TEUseEI.UserTE->getMainOp())) {
TEInsertBlock = PHI->getIncomingBlock(TEUseEI.EdgeIdx);
+ TEInsertPt = TEInsertBlock->getTerminator();
} else {
TEInsertBlock = TEInsertPt->getParent();
}
@@ -9106,9 +9107,10 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, ArrayRef<Value *> VL,
const Instruction *InsertPt =
UserPHI ? UserPHI->getIncomingBlock(UseEI.EdgeIdx)->getTerminator()
: &getLastInstructionInBundle(UseEI.UserTE);
- if (!UserPHI && TEInsertPt == InsertPt) {
- // If 2 gathers are operands of the same non-PHI entry,
- // compare operands indices, use the earlier one as the base.
+ if (TEInsertPt == InsertPt) {
+ // If 2 gathers are operands of the same entry (regardless of wether
+ // user is PHI or else), compare operands indices, use the earlier one
+ // as the base.
if (TEUseEI.UserTE == UseEI.UserTE && TEUseEI.EdgeIdx < UseEI.EdgeIdx)
continue;
// If the user instruction is used for some reason in different
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll b/llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll
index 28e0b06f6967368..e5d7ad138b4def2 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/matching-gather-nodes-phi-users.ll
@@ -8,7 +8,7 @@
; YAML: Function: test
; YAML: Args:
; YAML: - String: 'Stores SLP vectorized with cost '
-; YAML: - Cost: '-3'
+; YAML: - Cost: '-6'
; YAML: - String: ' and with tree size '
; YAML: - TreeSize: '14'
; YAML: ...
More information about the llvm-commits
mailing list