[llvm] LoopVectorize: guard marking iv as scalar; fix bug (PR #88730)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 03:33:32 PDT 2024


================
@@ -3875,6 +3875,13 @@ void LoopVectorizationCostModel::collectLoopScalars(ElementCount VF) {
     if (!ScalarInd)
       continue;
 
+    // If the induction variable update is a fixed-order recurrence, neither the
+    // induction variable or its update should be marked scalar after
+    // vectorization.
+    auto *IndUpdatePhi = dyn_cast<PHINode>(IndUpdate);
+    if (IndUpdatePhi && Legal->isFixedOrderRecurrence(IndUpdatePhi))
----------------
artagnon wrote:

I don't think `Ind` can be an induction var _and_ a fixed-order recurrence at the same time.

```
  for (const auto &Induction : Legal->getInductionVars()) {
    auto *Ind = Induction.first;
    auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));
```

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


More information about the llvm-commits mailing list