@@ -21680,58 +21680,6 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
21680
21680
return Changed;
21681
21681
}
21682
21682
21683
- bool SLPVectorizerPass::tryToVectorize(Instruction *I, BoUpSLP &R) {
21684
- if (!I)
21685
- return false;
21686
-
21687
- if (!isa<BinaryOperator, CmpInst>(I) || isa<VectorType>(I->getType()))
21688
- return false;
21689
-
21690
- Value *P = I->getParent();
21691
-
21692
- // Vectorize in current basic block only.
21693
- auto *Op0 = dyn_cast<Instruction>(I->getOperand(0));
21694
- auto *Op1 = dyn_cast<Instruction>(I->getOperand(1));
21695
- if (!Op0 || !Op1 || Op0->getParent() != P || Op1->getParent() != P ||
21696
- R.isDeleted(Op0) || R.isDeleted(Op1))
21697
- return false;
21698
-
21699
- // First collect all possible candidates
21700
- SmallVector<std::pair<Value *, Value *>, 4> Candidates;
21701
- Candidates.emplace_back(Op0, Op1);
21702
-
21703
- auto *A = dyn_cast<BinaryOperator>(Op0);
21704
- auto *B = dyn_cast<BinaryOperator>(Op1);
21705
- // Try to skip B.
21706
- if (A && B && B->hasOneUse()) {
21707
- auto *B0 = dyn_cast<BinaryOperator>(B->getOperand(0));
21708
- auto *B1 = dyn_cast<BinaryOperator>(B->getOperand(1));
21709
- if (B0 && B0->getParent() == P && !R.isDeleted(B0))
21710
- Candidates.emplace_back(A, B0);
21711
- if (B1 && B1->getParent() == P && !R.isDeleted(B1))
21712
- Candidates.emplace_back(A, B1);
21713
- }
21714
- // Try to skip A.
21715
- if (B && A && A->hasOneUse()) {
21716
- auto *A0 = dyn_cast<BinaryOperator>(A->getOperand(0));
21717
- auto *A1 = dyn_cast<BinaryOperator>(A->getOperand(1));
21718
- if (A0 && A0->getParent() == P && !R.isDeleted(A0))
21719
- Candidates.emplace_back(A0, B);
21720
- if (A1 && A1->getParent() == P && !R.isDeleted(A1))
21721
- Candidates.emplace_back(A1, B);
21722
- }
21723
-
21724
- if (Candidates.size() == 1)
21725
- return tryToVectorizeList({Op0, Op1}, R);
21726
-
21727
- // We have multiple options. Try to pick the single best.
21728
- std::optional<int> BestCandidate = R.findBestRootPair(Candidates);
21729
- if (!BestCandidate)
21730
- return false;
21731
- return tryToVectorizeList(
21732
- {Candidates[*BestCandidate].first, Candidates[*BestCandidate].second}, R);
21733
- }
21734
-
21735
21683
namespace {
21736
21684
21737
21685
/// Model horizontal reductions.
@@ -23744,6 +23692,58 @@ bool SLPVectorizerPass::vectorizeHorReduction(
23744
23692
return Res;
23745
23693
}
23746
23694
23695
+ bool SLPVectorizerPass::tryToVectorize(Instruction *I, BoUpSLP &R) {
23696
+ if (!I)
23697
+ return false;
23698
+
23699
+ if (!isa<BinaryOperator, CmpInst>(I) || isa<VectorType>(I->getType()))
23700
+ return false;
23701
+
23702
+ Value *P = I->getParent();
23703
+
23704
+ // Vectorize in current basic block only.
23705
+ auto *Op0 = dyn_cast<Instruction>(I->getOperand(0));
23706
+ auto *Op1 = dyn_cast<Instruction>(I->getOperand(1));
23707
+ if (!Op0 || !Op1 || Op0->getParent() != P || Op1->getParent() != P ||
23708
+ R.isDeleted(Op0) || R.isDeleted(Op1))
23709
+ return false;
23710
+
23711
+ // First collect all possible candidates
23712
+ SmallVector<std::pair<Value *, Value *>, 4> Candidates;
23713
+ Candidates.emplace_back(Op0, Op1);
23714
+
23715
+ auto *A = dyn_cast<BinaryOperator>(Op0);
23716
+ auto *B = dyn_cast<BinaryOperator>(Op1);
23717
+ // Try to skip B.
23718
+ if (A && B && B->hasOneUse()) {
23719
+ auto *B0 = dyn_cast<BinaryOperator>(B->getOperand(0));
23720
+ auto *B1 = dyn_cast<BinaryOperator>(B->getOperand(1));
23721
+ if (B0 && B0->getParent() == P && !R.isDeleted(B0))
23722
+ Candidates.emplace_back(A, B0);
23723
+ if (B1 && B1->getParent() == P && !R.isDeleted(B1))
23724
+ Candidates.emplace_back(A, B1);
23725
+ }
23726
+ // Try to skip A.
23727
+ if (B && A && A->hasOneUse()) {
23728
+ auto *A0 = dyn_cast<BinaryOperator>(A->getOperand(0));
23729
+ auto *A1 = dyn_cast<BinaryOperator>(A->getOperand(1));
23730
+ if (A0 && A0->getParent() == P && !R.isDeleted(A0))
23731
+ Candidates.emplace_back(A0, B);
23732
+ if (A1 && A1->getParent() == P && !R.isDeleted(A1))
23733
+ Candidates.emplace_back(A1, B);
23734
+ }
23735
+
23736
+ if (Candidates.size() == 1)
23737
+ return tryToVectorizeList({Op0, Op1}, R);
23738
+
23739
+ // We have multiple options. Try to pick the single best.
23740
+ std::optional<int> BestCandidate = R.findBestRootPair(Candidates);
23741
+ if (!BestCandidate)
23742
+ return false;
23743
+ return tryToVectorizeList(
23744
+ {Candidates[*BestCandidate].first, Candidates[*BestCandidate].second}, R);
23745
+ }
23746
+
23747
23747
bool SLPVectorizerPass::vectorizeRootInstruction(PHINode *P, Instruction *Root,
23748
23748
BasicBlock *BB, BoUpSLP &R) {
23749
23749
SmallVector<WeakTrackingVH> PostponedInsts;
0 commit comments