[NFC] SLVectorizer comparator refactoring that preserves behavior (#84966)
Spinning off from #79321 / 35f4592 - looked like the comparator could be
simplified & made more clear/less risk of leaving hidden bugs.
This commit is contained in:
@@ -16614,36 +16614,11 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
|
||||
if (Opcodes1.size() > Opcodes2.size())
|
||||
return false;
|
||||
for (int I = 0, E = Opcodes1.size(); I < E; ++I) {
|
||||
// Undefs are compatible with any other value.
|
||||
if (isa<UndefValue>(Opcodes1[I]) || isa<UndefValue>(Opcodes2[I])) {
|
||||
if (isa<UndefValue>(Opcodes1[I]) && isa<UndefValue>(Opcodes2[I]))
|
||||
continue;
|
||||
if (isa<Instruction>(Opcodes1[I])) {
|
||||
assert(isa<UndefValue>(Opcodes2[I]) && "Expected 2nd undef value");
|
||||
return true;
|
||||
}
|
||||
if (isa<Instruction>(Opcodes2[I])) {
|
||||
assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
|
||||
return false;
|
||||
}
|
||||
if (isa<Constant>(Opcodes1[I]) && !isa<UndefValue>(Opcodes1[I])) {
|
||||
assert(isa<UndefValue>(Opcodes2[I]) && "Expected 2nd undef value");
|
||||
return true;
|
||||
}
|
||||
if (isa<Constant>(Opcodes2[I]) && !isa<UndefValue>(Opcodes2[I])) {
|
||||
assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
|
||||
return false;
|
||||
}
|
||||
if (!isa<UndefValue>(Opcodes2[I])) {
|
||||
assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
|
||||
return false;
|
||||
}
|
||||
assert(!isa<UndefValue>(Opcodes1[I]) && isa<UndefValue>(Opcodes2[I]) &&
|
||||
"Expected 1st non-undef and 2nd undef value");
|
||||
return true;
|
||||
}
|
||||
if (auto *I1 = dyn_cast<Instruction>(Opcodes1[I]))
|
||||
if (auto *I2 = dyn_cast<Instruction>(Opcodes2[I])) {
|
||||
{
|
||||
// Instructions come first.
|
||||
auto *I1 = dyn_cast<Instruction>(Opcodes1[I]);
|
||||
auto *I2 = dyn_cast<Instruction>(Opcodes2[I]);
|
||||
if (I1 && I2) {
|
||||
DomTreeNodeBase<BasicBlock> *NodeI1 = DT->getNode(I1->getParent());
|
||||
DomTreeNodeBase<BasicBlock> *NodeI2 = DT->getNode(I2->getParent());
|
||||
if (!NodeI1)
|
||||
@@ -16660,20 +16635,44 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
|
||||
continue;
|
||||
return I1->getOpcode() < I2->getOpcode();
|
||||
}
|
||||
if (isa<Constant>(Opcodes1[I]) && isa<Constant>(Opcodes2[I]))
|
||||
continue;
|
||||
if (isa<Instruction>(Opcodes1[I]) && !isa<Instruction>(Opcodes2[I]))
|
||||
return true;
|
||||
if (!isa<Instruction>(Opcodes1[I]) && isa<Instruction>(Opcodes2[I]))
|
||||
return false;
|
||||
if (isa<Constant>(Opcodes1[I]) && !isa<Constant>(Opcodes2[I]))
|
||||
return true;
|
||||
if (!isa<Constant>(Opcodes1[I]) && isa<Constant>(Opcodes2[I]))
|
||||
return false;
|
||||
if (Opcodes1[I]->getValueID() < Opcodes2[I]->getValueID())
|
||||
return true;
|
||||
if (Opcodes1[I]->getValueID() > Opcodes2[I]->getValueID())
|
||||
return false;
|
||||
if (I1)
|
||||
return true;
|
||||
if (I2)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
// Non-undef constants come next.
|
||||
bool C1 = isa<Constant>(Opcodes1[I]) && !isa<UndefValue>(Opcodes1[I]);
|
||||
bool C2 = isa<Constant>(Opcodes2[I]) && !isa<UndefValue>(Opcodes2[I]);
|
||||
if (C1 && C2)
|
||||
continue;
|
||||
if (C1)
|
||||
return true;
|
||||
if (C2)
|
||||
return false;
|
||||
}
|
||||
bool U1 = isa<UndefValue>(Opcodes1[I]);
|
||||
bool U2 = isa<UndefValue>(Opcodes2[I]);
|
||||
{
|
||||
// Non-constant non-instructions come next.
|
||||
if (!U1 && !U2) {
|
||||
auto ValID1 = Opcodes1[I]->getValueID();
|
||||
auto ValID2 = Opcodes2[I]->getValueID();
|
||||
if (ValID1 == ValID2)
|
||||
continue;
|
||||
if (ValID1 < ValID2)
|
||||
return true;
|
||||
if (ValID1 > ValID2)
|
||||
return false;
|
||||
}
|
||||
if (!U1)
|
||||
return true;
|
||||
if (!U2)
|
||||
return false;
|
||||
}
|
||||
// Undefs come last.
|
||||
assert(U1 && U2);
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user