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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 10:19:43 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))
----------------
david-arm wrote:

Does being a fixed-order recurrence guarantee that it will be vectorised? I realise the cost model in getInstructionCost seems to think so, but I wasn't sure if the cost model might also be broken.

Also, it looks like we're treating this as scalar-after-vectorisation because a user of the update is in the WorkList. I must admit to finding this code very complicated so I don't fully understand it, but I wonder if there is a way to stop it from appearing in the WorkList early on?

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


More information about the llvm-commits mailing list