[llvm] [SLP] NFC. Refactor getSameOpcode and reduce for loop iterations. (PR #122241)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 07:48:02 PST 2025


================
@@ -955,18 +953,18 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
   }();
   // Check for one alternate opcode from another BinaryOperator.
   // TODO - generalize to support all operators (types, calls etc.).
-  auto *IBase = cast<Instruction>(V);
   Intrinsic::ID BaseID = 0;
   SmallVector<VFInfo> BaseMappings;
-  if (auto *CallBase = dyn_cast<CallInst>(IBase)) {
+  if (auto *CallBase = dyn_cast<CallInst>(MainOp)) {
     BaseID = getVectorIntrinsicIDForCall(CallBase, &TLI);
     BaseMappings = VFDatabase(*CallBase).getMappings(*CallBase);
     if (!isTriviallyVectorizable(BaseID) && BaseMappings.empty())
       return InstructionsState::invalid();
   }
   bool AnyPoison = InstCnt != VL.size();
-  for (int Cnt = 0, E = VL.size(); Cnt < E; Cnt++) {
-    auto *I = dyn_cast<Instruction>(VL[Cnt]);
+  // Skip MainOp.
+  while (++It != VL.end()) {
----------------
alexey-bataev wrote:

```suggestion
  for (Value *V : iterator_tange(It, VL.end())) {
```

https://github.com/llvm/llvm-project/pull/122241


More information about the llvm-commits mailing list