Skip to content

Commit 0b5d6c0

Browse files
committed
Review comments
Change-Id: I5bb81e7e3177f3cf196e682786a3de966a7a0014
1 parent b450a7c commit 0b5d6c0

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ isFixedVectorShuffle(ArrayRef<Value *> VL, SmallVectorImpl<int> &Mask,
795795
}
796796

797797
/// \returns True if Extract{Value,Element} instruction extracts element Idx.
798-
static std::optional<unsigned> getExtractIndex(Instruction *E) {
798+
static std::optional<unsigned> getExtractIndex(const Instruction *E) {
799799
unsigned Opcode = E->getOpcode();
800800
assert((Opcode == Instruction::ExtractElement ||
801801
Opcode == Instruction::ExtractValue) &&
@@ -22691,37 +22691,36 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2269122691
return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2269222692
InstructionsState S = getSameOpcode({I1, I2}, *TLI);
2269322693
if (S && !S.isAltShuffle()) {
22694-
if (!isa<ExtractElementInst>(I1) || !isa<ExtractElementInst>(I2))
22694+
const auto *E1 = dyn_cast<ExtractElementInst>(I1);
22695+
const auto *E2 = dyn_cast<ExtractElementInst>(I2);
22696+
if (!E1 || !E2)
2269522697
continue;
2269622698

22697-
auto E1 = cast<ExtractElementInst>(I1);
22698-
auto E2 = cast<ExtractElementInst>(I2);
2269922699
// Sort on ExtractElementInsts primarily by vector operands. Prefer
22700-
// program order of the vector operands
22700+
// program order of the vector operands.
2270122701
if (E1->getVectorOperand() != E2->getVectorOperand()) {
22702-
Instruction *V1 = dyn_cast<Instruction>(E1->getVectorOperand());
22703-
Instruction *V2 = dyn_cast<Instruction>(E2->getVectorOperand());
22702+
const Instruction *V1 =
22703+
dyn_cast<Instruction>(E1->getVectorOperand());
22704+
const Instruction *V2 =
22705+
dyn_cast<Instruction>(E2->getVectorOperand());
2270422706
if (!V1 || !V2)
2270522707
continue;
2270622708
if (V1->getParent() != V2->getParent())
2270722709
continue;
2270822710
return V1->comesBefore(V2);
2270922711
}
22710-
// If we have the same vector operand, try to sort by constant index
22711-
auto Id1 = E1->getIndexOperand();
22712-
auto Id2 = E2->getIndexOperand();
22712+
// If we have the same vector operand, try to sort by constant
22713+
// index.
22714+
std::optional<unsigned> Id1 = getExtractIndex(E1);
22715+
std::optional<unsigned> Id2 = getExtractIndex(E2);
2271322716
// Bring constants to the top
22714-
if (isa<ConstantInt>(Id1) && !isa<ConstantInt>(Id2))
22717+
if (Id1 && !Id2)
2271522718
return true;
22716-
if (!isa<ConstantInt>(Id1) && isa<ConstantInt>(Id2))
22719+
if (!Id1 && Id2)
2271722720
return false;
22718-
if (isa<ConstantInt>(Id1) && isa<ConstantInt>(Id2)) {
22719-
auto C1 = cast<ConstantInt>(Id1);
22720-
auto C2 = cast<ConstantInt>(Id2);
22721-
// First elements first
22722-
return C1->getValue().getZExtValue() <
22723-
C2->getValue().getZExtValue();
22724-
}
22721+
// First elements come first.
22722+
if (Id1 && Id2)
22723+
return *Id1 < *Id2;
2272522724

2272622725
continue;
2272722726
}

0 commit comments

Comments
 (0)