Skip to content

Commit 76e7657

Browse files
Replace depth with size
1 parent 1bca086 commit 76e7657

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,21 +3178,21 @@ bool VectorCombine::foldCastFromReductions(Instruction &I) {
31783178
/// vector reduction intrinsic (e.g., vector_reduce_add) by only following
31793179
/// chains of shuffles and binary operators (in any combination/order).
31803180
/// The search does not go deeper than the given Depth.
3181-
static bool feedsIntoVectorReduction(ShuffleVectorInst *SVI, unsigned Depth) {
3181+
static bool feedsIntoVectorReduction(ShuffleVectorInst *SVI) {
3182+
constexpr unsigned MaxVisited = 32;
31823183
SmallPtrSet<Instruction *, 8> Visited;
3183-
SmallVector<std::pair<Instruction *, unsigned>, 4> WorkList;
3184+
SmallVector<Instruction *, 4> WorkList;
31843185
bool FoundReduction = false;
31853186

3186-
WorkList.push_back({SVI, 0});
3187+
WorkList.push_back(SVI);
31873188
while (!WorkList.empty()) {
3188-
auto [I, CurDepth] = WorkList.pop_back_val();
3189-
if (CurDepth > Depth)
3190-
return false;
3191-
3189+
Instruction *I = WorkList.pop_back_val();
31923190
for (User *U : I->users()) {
3193-
auto *UI = dyn_cast<Instruction>(U);
3191+
auto *UI = cast<Instruction>(U);
31943192
if (!UI || !Visited.insert(UI).second)
31953193
continue;
3194+
if (Visited.size() > MaxVisited)
3195+
return false;
31963196
if (auto *II = dyn_cast<IntrinsicInst>(UI)) {
31973197
// More than one reduction reached
31983198
if (FoundReduction)
@@ -3216,7 +3216,8 @@ static bool feedsIntoVectorReduction(ShuffleVectorInst *SVI, unsigned Depth) {
32163216

32173217
if (!isa<BinaryOperator>(UI) && !isa<ShuffleVectorInst>(UI))
32183218
return false;
3219-
WorkList.emplace_back(UI, CurDepth + 1);
3219+
3220+
WorkList.emplace_back(UI);;
32203221
}
32213222
}
32223223
return FoundReduction;
@@ -3560,7 +3561,7 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
35603561
LLVM_DEBUG(dbgs() << " CostBefore: " << CostBefore
35613562
<< " vs CostAfter: " << CostAfter << "\n");
35623563
if (CostBefore < CostAfter ||
3563-
(CostBefore == CostAfter && !feedsIntoVectorReduction(SVI, 8)))
3564+
(CostBefore == CostAfter && !feedsIntoVectorReduction(SVI)))
35643565
return false;
35653566

35663567
// The cost model has passed, create the new instructions.

0 commit comments

Comments
 (0)