@@ -16614,36 +16614,11 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
16614
16614
if (Opcodes1.size() > Opcodes2.size())
16615
16615
return false;
16616
16616
for (int I = 0, E = Opcodes1.size(); I < E; ++I) {
16617
- // Undefs are compatible with any other value.
16618
- if (isa<UndefValue>(Opcodes1[I]) || isa<UndefValue>(Opcodes2[I])) {
16619
- if (isa<UndefValue>(Opcodes1[I]) && isa<UndefValue>(Opcodes2[I]))
16620
- continue;
16621
- if (isa<Instruction>(Opcodes1[I])) {
16622
- assert(isa<UndefValue>(Opcodes2[I]) && "Expected 2nd undef value");
16623
- return true;
16624
- }
16625
- if (isa<Instruction>(Opcodes2[I])) {
16626
- assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
16627
- return false;
16628
- }
16629
- if (isa<Constant>(Opcodes1[I]) && !isa<UndefValue>(Opcodes1[I])) {
16630
- assert(isa<UndefValue>(Opcodes2[I]) && "Expected 2nd undef value");
16631
- return true;
16632
- }
16633
- if (isa<Constant>(Opcodes2[I]) && !isa<UndefValue>(Opcodes2[I])) {
16634
- assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
16635
- return false;
16636
- }
16637
- if (!isa<UndefValue>(Opcodes2[I])) {
16638
- assert(isa<UndefValue>(Opcodes1[I]) && "Expected 1st undef value");
16639
- return false;
16640
- }
16641
- assert(!isa<UndefValue>(Opcodes1[I]) && isa<UndefValue>(Opcodes2[I]) &&
16642
- "Expected 1st non-undef and 2nd undef value");
16643
- return true;
16644
- }
16645
- if (auto *I1 = dyn_cast<Instruction>(Opcodes1[I]))
16646
- if (auto *I2 = dyn_cast<Instruction>(Opcodes2[I])) {
16617
+ {
16618
+ // Instructions come first.
16619
+ auto *I1 = dyn_cast<Instruction>(Opcodes1[I]);
16620
+ auto *I2 = dyn_cast<Instruction>(Opcodes2[I]);
16621
+ if (I1 && I2) {
16647
16622
DomTreeNodeBase<BasicBlock> *NodeI1 = DT->getNode(I1->getParent());
16648
16623
DomTreeNodeBase<BasicBlock> *NodeI2 = DT->getNode(I2->getParent());
16649
16624
if (!NodeI1)
@@ -16660,20 +16635,44 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
16660
16635
continue;
16661
16636
return I1->getOpcode() < I2->getOpcode();
16662
16637
}
16663
- if (isa<Constant>(Opcodes1[I]) && isa<Constant>(Opcodes2[I]))
16664
- continue;
16665
- if (isa<Instruction>(Opcodes1[I]) && !isa<Instruction>(Opcodes2[I]))
16666
- return true;
16667
- if (!isa<Instruction>(Opcodes1[I]) && isa<Instruction>(Opcodes2[I]))
16668
- return false;
16669
- if (isa<Constant>(Opcodes1[I]) && !isa<Constant>(Opcodes2[I]))
16670
- return true;
16671
- if (!isa<Constant>(Opcodes1[I]) && isa<Constant>(Opcodes2[I]))
16672
- return false;
16673
- if (Opcodes1[I]->getValueID() < Opcodes2[I]->getValueID())
16674
- return true;
16675
- if (Opcodes1[I]->getValueID() > Opcodes2[I]->getValueID())
16676
- return false;
16638
+ if (I1)
16639
+ return true;
16640
+ if (I2)
16641
+ return false;
16642
+ }
16643
+ {
16644
+ // Non-undef constants come next.
16645
+ bool C1 = isa<Constant>(Opcodes1[I]) && !isa<UndefValue>(Opcodes1[I]);
16646
+ bool C2 = isa<Constant>(Opcodes2[I]) && !isa<UndefValue>(Opcodes2[I]);
16647
+ if (C1 && C2)
16648
+ continue;
16649
+ if (C1)
16650
+ return true;
16651
+ if (C2)
16652
+ return false;
16653
+ }
16654
+ bool U1 = isa<UndefValue>(Opcodes1[I]);
16655
+ bool U2 = isa<UndefValue>(Opcodes2[I]);
16656
+ {
16657
+ // Non-constant non-instructions come next.
16658
+ if (!U1 && !U2) {
16659
+ auto ValID1 = Opcodes1[I]->getValueID();
16660
+ auto ValID2 = Opcodes2[I]->getValueID();
16661
+ if (ValID1 == ValID2)
16662
+ continue;
16663
+ if (ValID1 < ValID2)
16664
+ return true;
16665
+ if (ValID1 > ValID2)
16666
+ return false;
16667
+ }
16668
+ if (!U1)
16669
+ return true;
16670
+ if (!U2)
16671
+ return false;
16672
+ }
16673
+ // Undefs come last.
16674
+ assert(U1 && U2);
16675
+ continue;
16677
16676
}
16678
16677
return false;
16679
16678
};
0 commit comments