Skip to content

Commit 58868e4

Browse files
author
Leon Clark
committed
Address comments.
1 parent b50f692 commit 58868e4

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
34053405
bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
34063406
auto *InputShuffle = dyn_cast<ShuffleVectorInst>(&I);
34073407
if (!InputShuffle)
3408-
return {};
3408+
return false;
34093409

34103410
auto *OldLoad = dyn_cast<LoadInst>(InputShuffle->getOperand(0u));
34113411
if (!OldLoad || !OldLoad->isSimple())
@@ -3415,34 +3415,31 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
34153415
if (!VecTy)
34163416
return false;
34173417

3418-
auto IsPoisonOrUndef = [](Value *V) -> bool {
3419-
if (auto *C = dyn_cast<Constant>(V)) {
3420-
return isa<PoisonValue>(C) || isa<UndefValue>(C);
3421-
}
3422-
return false;
3423-
};
3424-
3418+
// Search all uses of `I`. If all uses are shufflevector ops, and the second
3419+
// operands are all poison values, find the minimum and maximum indices of
3420+
// the vector elements referenced by all shuffle masks.
3421+
// Otherwise return `std::nullopt`.
34253422
using IndexRange = std::pair<int, int>;
34263423
auto GetIndexRangeInShuffles = [&]() -> std::optional<IndexRange> {
3427-
auto OutputRange = IndexRange(VecTy->getNumElements(), -1);
3424+
IndexRange OutputRange = IndexRange(VecTy->getNumElements(), -1);
34283425
for (auto &Use : I.uses()) {
34293426
// All uses must be ShuffleVector instructions.
34303427
auto *Shuffle = dyn_cast<ShuffleVectorInst>(Use.getUser());
34313428
if (!Shuffle)
3432-
return {};
3429+
return std::nullopt;
34333430

34343431
// Get index range for value.
3435-
auto *Op0 = Shuffle->getOperand(0u);
3436-
auto *Op1 = Shuffle->getOperand(1u);
3437-
if (!IsPoisonOrUndef(Op1))
3438-
return {};
3432+
auto *Op0 = Shuffle->getOperand(0);
3433+
auto *Op1 = Shuffle->getOperand(1);
3434+
if (!isa<PoisonValue>(Op1) && !isa<UndefValue>(Op1))
3435+
return std::nullopt;
34393436

34403437
// Find the min and max indices used by the ShuffleVector instruction.
3441-
auto Mask = Shuffle->getShuffleMask();
3438+
ArrayRef<int> Mask = Shuffle->getShuffleMask();
34423439
auto *Op0Ty = cast<FixedVectorType>(Op0->getType());
34433440
auto NumElems = int(Op0Ty->getNumElements());
34443441

3445-
for (auto Index : Mask) {
3442+
for (int Index : Mask) {
34463443
if (Index >= 0) {
34473444
Index %= NumElems;
34483445
OutputRange.first = std::min(Index, OutputRange.first);
@@ -3452,15 +3449,18 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
34523449
}
34533450

34543451
if (OutputRange.second < OutputRange.first)
3455-
return {};
3452+
return std::nullopt;
34563453

34573454
return OutputRange;
34583455
};
34593456

3457+
// Find the range of vector elements used by shufflevector ops, if possible.
34603458
if (auto Indices = GetIndexRangeInShuffles()) {
3461-
auto OldSize = VecTy->getNumElements();
3462-
auto NewSize = Indices->second + 1u;
3459+
unsigned OldSize = VecTy->getNumElements();
3460+
unsigned NewSize = Indices->second + 1u;
34633461

3462+
// If the range of vector elements is smaller than the full load, attempt
3463+
// to create a smaller load.
34643464
if (NewSize < OldSize) {
34653465
auto Builder = IRBuilder(&I);
34663466
Builder.SetCurrentDebugLocation(I.getDebugLoc());

0 commit comments

Comments
 (0)