Skip to content

Commit 41b6e54

Browse files
author
Leon Clark
committed
Fix test failures.
1 parent 365522e commit 41b6e54

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,7 +3745,7 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37453745

37463746
// Get the range of vector elements used by shufflevector instructions.
37473747
if (std::optional<IndexRange> Indices = GetIndexRangeInShuffles()) {
3748-
unsigned const NewNumElements = (Indices->second + 1u) - Indices->first;
3748+
unsigned const NewNumElements = (Indices->second + 1) - Indices->first;
37493749

37503750
// If the range of vector elements is smaller than the full load, attempt
37513751
// to create a smaller load.
@@ -3768,7 +3768,7 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37683768
using UseEntry = std::pair<ShuffleVectorInst *, std::vector<int>>;
37693769
SmallVector<UseEntry, 4u> NewUses;
37703770
unsigned const LowOffset = Indices->first;
3771-
unsigned const HighOffset = OldNumElements - NewNumElements;
3771+
unsigned const HighOffset = OldNumElements - (Indices->second + 1);
37723772

37733773
for (llvm::Use &Use : I.uses()) {
37743774
auto *Shuffle = cast<ShuffleVectorInst>(Use.getUser());
@@ -3777,10 +3777,14 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37773777
// Create entry for new use.
37783778
NewUses.push_back({Shuffle, {}});
37793779
std::vector<int> &NewMask = NewUses.back().second;
3780-
for (int Index : OldMask)
3781-
NewMask.push_back(Index >= static_cast<int>(OldNumElements)
3782-
? Index - HighOffset
3783-
: Index - LowOffset);
3780+
for (int Index : OldMask) {
3781+
int NewIndex = Index >= static_cast<int>(OldNumElements)
3782+
? Index - LowOffset - HighOffset
3783+
: Index - LowOffset;
3784+
if (NewIndex >= static_cast<int>(NewNumElements * 2u))
3785+
return false;
3786+
NewMask.push_back(NewIndex);
3787+
}
37843788

37853789
// Update costs.
37863790
OldCost +=

0 commit comments

Comments
 (0)