[PATCH] D115112: [LV] Remove dead IV casts using VPlan (NFC).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 7 08:15:50 PST 2021


fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:315
+    IVUsers.append(IV->user_begin(), IV->user_end());
+    while (!IVUsers.empty()) {
+      VPRecipeBase *R = cast<VPRecipeBase>(IVUsers.pop_back_val());
----------------
Ayal wrote:
> (This cannot loop forever because Casts excludes the header phi chaining Casts into a cycle.)
> 
> There typically will be a few Casts if any, but it does seem somewhat wasteful to go through all users of all Casts. Perhaps loop until the last Cast is reached, saving the redundant traversal over its users? (And reducing the risk of infinite loop if something went wrong?)
> Can also repeatedly search for a single next cast among the users of the current CastDef, stopping as soon as one is found, instead of always appending all users for traversal.
I adjusted the loop to keep track of the number of casts already removed in the loop and only iterate until `NumDeadCasts == Casts.size()`. That should ensure that we bail out as soon as all casts have been visited, without adding the need for an extra bailout.

It also removes the need for the assertion below I think, because this is now guaranteed by the loop directly. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115112/new/

https://reviews.llvm.org/D115112



More information about the llvm-commits mailing list