@@ -929,6 +929,29 @@ getInterchangeableInstruction(Instruction *I) {
929
929
return PII;
930
930
}
931
931
932
+ /// \returns the Op and operands which \p I convert to.
933
+ static std::pair<Value *, SmallVector<Value *>>
934
+ getInterchangeableInstruction(Instruction *I, Instruction *MainOp,
935
+ Instruction *AltOp) {
936
+ SmallVector<InterchangeableInstruction> IIList =
937
+ getInterchangeableInstruction(I);
938
+ auto Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
939
+ return II.Opcode == MainOp->getOpcode();
940
+ });
941
+ Value *SelectedOp;
942
+ if (Iter == IIList.end()) {
943
+ Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
944
+ return II.Opcode == AltOp->getOpcode();
945
+ });
946
+ assert(Iter != IIList.end() &&
947
+ "Cannot find an interchangeable instruction.");
948
+ SelectedOp = AltOp;
949
+ } else {
950
+ SelectedOp = MainOp;
951
+ }
952
+ return std::make_pair(SelectedOp, Iter->Ops);
953
+ }
954
+
932
955
/// \returns true if \p Opcode is allowed as part of the main/alternate
933
956
/// instruction for SLP vectorization.
934
957
///
@@ -2484,22 +2507,8 @@ class BoUpSLP {
2484
2507
OpsVec[OpIdx].resize(NumLanes);
2485
2508
for (auto [I, V] : enumerate(VL)) {
2486
2509
assert(isa<Instruction>(V) && "Expected instruction");
2487
- SmallVector<InterchangeableInstruction> IIList =
2488
- getInterchangeableInstruction(cast<Instruction>(V));
2489
- Value *SelectedOp;
2490
- auto Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
2491
- return II.Opcode == S.MainOp->getOpcode();
2492
- });
2493
- if (Iter == IIList.end()) {
2494
- Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
2495
- return II.Opcode == S.AltOp->getOpcode();
2496
- });
2497
- SelectedOp = S.AltOp;
2498
- } else {
2499
- SelectedOp = S.MainOp;
2500
- }
2501
- assert(Iter != IIList.end() &&
2502
- "Cannot find an interchangeable instruction.");
2510
+ auto [SelectedOp, Ops] = getInterchangeableInstruction(
2511
+ cast<Instruction>(V), S.MainOp, S.AltOp);
2503
2512
// Our tree has just 3 nodes: the root and two operands.
2504
2513
// It is therefore trivial to get the APO. We only need to check the
2505
2514
// opcode of V and whether the operand at OpIdx is the LHS or RHS
@@ -2513,7 +2522,7 @@ class BoUpSLP {
2513
2522
bool IsInverseOperation = !isCommutative(cast<Instruction>(SelectedOp));
2514
2523
for (unsigned OpIdx : seq<unsigned>(NumOperands)) {
2515
2524
bool APO = (OpIdx == 0) ? false : IsInverseOperation;
2516
- OpsVec[OpIdx][I] = {Iter-> Ops[OpIdx], APO, false};
2525
+ OpsVec[OpIdx][I] = {Ops[OpIdx], APO, false};
2517
2526
}
2518
2527
}
2519
2528
}
@@ -3417,20 +3426,10 @@ class BoUpSLP {
3417
3426
for (unsigned OpIdx : seq<unsigned>(NumOperands))
3418
3427
Operands[OpIdx].resize(NumLanes);
3419
3428
for (auto [I, V] : enumerate(Scalars)) {
3420
- SmallVector<InterchangeableInstruction> IIList =
3421
- getInterchangeableInstruction(cast<Instruction>(V));
3422
- auto Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
3423
- return II.Opcode == MainOp->getOpcode();
3424
- });
3425
- if (Iter == IIList.end())
3426
- Iter = find_if(IIList, [&](const InterchangeableInstruction &II) {
3427
- return II.Opcode == AltOp->getOpcode();
3428
- });
3429
- assert(Iter != IIList.end() &&
3430
- "Cannot find an interchangeable instruction.");
3431
- assert(Iter->Ops.size() == NumOperands &&
3432
- "Expected same number of operands");
3433
- for (auto [J, Op] : enumerate(Iter->Ops))
3429
+ auto [SelectedOp, Ops] =
3430
+ getInterchangeableInstruction(cast<Instruction>(V), MainOp, AltOp);
3431
+ assert(Ops.size() == NumOperands && "Expected same number of operands");
3432
+ for (auto [J, Op] : enumerate(Ops))
3434
3433
Operands[J][I] = Op;
3435
3434
}
3436
3435
}
0 commit comments