Skip to content

Commit 3afabd1

Browse files
author
Leon Clark
committed
Address comments.
1 parent 125c3f2 commit 3afabd1

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
@@ -3698,7 +3698,7 @@ bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
36983698
bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
36993699
auto *InputShuffle = dyn_cast<ShuffleVectorInst>(&I);
37003700
if (!InputShuffle)
3701-
return {};
3701+
return false;
37023702

37033703
auto *OldLoad = dyn_cast<LoadInst>(InputShuffle->getOperand(0u));
37043704
if (!OldLoad || !OldLoad->isSimple())
@@ -3708,34 +3708,31 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37083708
if (!VecTy)
37093709
return false;
37103710

3711-
auto IsPoisonOrUndef = [](Value *V) -> bool {
3712-
if (auto *C = dyn_cast<Constant>(V)) {
3713-
return isa<PoisonValue>(C) || isa<UndefValue>(C);
3714-
}
3715-
return false;
3716-
};
3717-
3711+
// Search all uses of `I`. If all uses are shufflevector ops, and the second
3712+
// operands are all poison values, find the minimum and maximum indices of
3713+
// the vector elements referenced by all shuffle masks.
3714+
// Otherwise return `std::nullopt`.
37183715
using IndexRange = std::pair<int, int>;
37193716
auto GetIndexRangeInShuffles = [&]() -> std::optional<IndexRange> {
3720-
auto OutputRange = IndexRange(VecTy->getNumElements(), -1);
3717+
IndexRange OutputRange = IndexRange(VecTy->getNumElements(), -1);
37213718
for (auto &Use : I.uses()) {
37223719
// All uses must be ShuffleVector instructions.
37233720
auto *Shuffle = dyn_cast<ShuffleVectorInst>(Use.getUser());
37243721
if (!Shuffle)
3725-
return {};
3722+
return std::nullopt;
37263723

37273724
// Get index range for value.
3728-
auto *Op0 = Shuffle->getOperand(0u);
3729-
auto *Op1 = Shuffle->getOperand(1u);
3730-
if (!IsPoisonOrUndef(Op1))
3731-
return {};
3725+
auto *Op0 = Shuffle->getOperand(0);
3726+
auto *Op1 = Shuffle->getOperand(1);
3727+
if (!isa<PoisonValue>(Op1) && !isa<UndefValue>(Op1))
3728+
return std::nullopt;
37323729

37333730
// Find the min and max indices used by the ShuffleVector instruction.
3734-
auto Mask = Shuffle->getShuffleMask();
3731+
ArrayRef<int> Mask = Shuffle->getShuffleMask();
37353732
auto *Op0Ty = cast<FixedVectorType>(Op0->getType());
37363733
auto NumElems = int(Op0Ty->getNumElements());
37373734

3738-
for (auto Index : Mask) {
3735+
for (int Index : Mask) {
37393736
if (Index >= 0) {
37403737
Index %= NumElems;
37413738
OutputRange.first = std::min(Index, OutputRange.first);
@@ -3745,15 +3742,18 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37453742
}
37463743

37473744
if (OutputRange.second < OutputRange.first)
3748-
return {};
3745+
return std::nullopt;
37493746

37503747
return OutputRange;
37513748
};
37523749

3750+
// Find the range of vector elements used by shufflevector ops, if possible.
37533751
if (auto Indices = GetIndexRangeInShuffles()) {
3754-
auto OldSize = VecTy->getNumElements();
3755-
auto NewSize = Indices->second + 1u;
3752+
unsigned OldSize = VecTy->getNumElements();
3753+
unsigned NewSize = Indices->second + 1u;
37563754

3755+
// If the range of vector elements is smaller than the full load, attempt
3756+
// to create a smaller load.
37573757
if (NewSize < OldSize) {
37583758
auto Builder = IRBuilder(&I);
37593759
Builder.SetCurrentDebugLocation(I.getDebugLoc());

0 commit comments

Comments
 (0)