Skip to content

Commit f2c6b30

Browse files
author
Leon Clark
committed
Address comments.
1 parent 5b63d6f commit f2c6b30

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
@@ -3490,7 +3490,7 @@ bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
34903490
bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
34913491
auto *InputShuffle = dyn_cast<ShuffleVectorInst>(&I);
34923492
if (!InputShuffle)
3493-
return {};
3493+
return false;
34943494

34953495
auto *OldLoad = dyn_cast<LoadInst>(InputShuffle->getOperand(0u));
34963496
if (!OldLoad || !OldLoad->isSimple())
@@ -3500,34 +3500,31 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
35003500
if (!VecTy)
35013501
return false;
35023502

3503-
auto IsPoisonOrUndef = [](Value *V) -> bool {
3504-
if (auto *C = dyn_cast<Constant>(V)) {
3505-
return isa<PoisonValue>(C) || isa<UndefValue>(C);
3506-
}
3507-
return false;
3508-
};
3509-
3503+
// Search all uses of `I`. If all uses are shufflevector ops, and the second
3504+
// operands are all poison values, find the minimum and maximum indices of
3505+
// the vector elements referenced by all shuffle masks.
3506+
// Otherwise return `std::nullopt`.
35103507
using IndexRange = std::pair<int, int>;
35113508
auto GetIndexRangeInShuffles = [&]() -> std::optional<IndexRange> {
3512-
auto OutputRange = IndexRange(VecTy->getNumElements(), -1);
3509+
IndexRange OutputRange = IndexRange(VecTy->getNumElements(), -1);
35133510
for (auto &Use : I.uses()) {
35143511
// All uses must be ShuffleVector instructions.
35153512
auto *Shuffle = dyn_cast<ShuffleVectorInst>(Use.getUser());
35163513
if (!Shuffle)
3517-
return {};
3514+
return std::nullopt;
35183515

35193516
// Get index range for value.
3520-
auto *Op0 = Shuffle->getOperand(0u);
3521-
auto *Op1 = Shuffle->getOperand(1u);
3522-
if (!IsPoisonOrUndef(Op1))
3523-
return {};
3517+
auto *Op0 = Shuffle->getOperand(0);
3518+
auto *Op1 = Shuffle->getOperand(1);
3519+
if (!isa<PoisonValue>(Op1) && !isa<UndefValue>(Op1))
3520+
return std::nullopt;
35243521

35253522
// Find the min and max indices used by the ShuffleVector instruction.
3526-
auto Mask = Shuffle->getShuffleMask();
3523+
ArrayRef<int> Mask = Shuffle->getShuffleMask();
35273524
auto *Op0Ty = cast<FixedVectorType>(Op0->getType());
35283525
auto NumElems = int(Op0Ty->getNumElements());
35293526

3530-
for (auto Index : Mask) {
3527+
for (int Index : Mask) {
35313528
if (Index >= 0) {
35323529
Index %= NumElems;
35333530
OutputRange.first = std::min(Index, OutputRange.first);
@@ -3537,15 +3534,18 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
35373534
}
35383535

35393536
if (OutputRange.second < OutputRange.first)
3540-
return {};
3537+
return std::nullopt;
35413538

35423539
return OutputRange;
35433540
};
35443541

3542+
// Find the range of vector elements used by shufflevector ops, if possible.
35453543
if (auto Indices = GetIndexRangeInShuffles()) {
3546-
auto OldSize = VecTy->getNumElements();
3547-
auto NewSize = Indices->second + 1u;
3544+
unsigned OldSize = VecTy->getNumElements();
3545+
unsigned NewSize = Indices->second + 1u;
35483546

3547+
// If the range of vector elements is smaller than the full load, attempt
3548+
// to create a smaller load.
35493549
if (NewSize < OldSize) {
35503550
auto Builder = IRBuilder(&I);
35513551
Builder.SetCurrentDebugLocation(I.getDebugLoc());

0 commit comments

Comments
 (0)