[PATCH] D112549: Adding patch and unittest to generalize ignorable induction casts in the LoopVectorizationLegality analysis.

Avery Laird via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 6 12:29:05 PDT 2021


avery-laird added a comment.

After investigating further into whether this patch can be merged with `getCastInsts()`, I think there are some difficulties in doing so.

`getCastInsts()` looks for a specific pattern that I'm not sure fits this case. For example (from comments in IVDescriptor.cpp), given an IR sequence like this:

  %for.body:
     %x = phi i64 [ 0, %ph ], [ %add, %for.body ]
     %casted_phi = and  %x, 2^n-1
     %add = add i64 %casted_phi, %step

The cast returned by getCastInsts() will be `%casted_phi`. The search is done by looking at the operands of `%add`, in this case finding `%casted_phi`, and testing whether `PSE.getSCEV(%x)` is equal to `PSE.getSCEV(%casted_phi)` under a predicate. Three differences are:

1. All instructions in the def-use chain must be binary, but `sext` for example is unary
2. Instructions must update the incoming value of the phi node to be considered (in this case through `%add`'s use of `%casted_phi`), but this patch should include instructions that don't update the induction Phi
3. Instructions need to be of the same type, but this patch should include instructions that may be casts from one type to another

In order to modify `getCastInsts()` to return the desired casts, at least these three things need to be changed. Additionally, by only changing `InductionCastsToIgnore`, just the cost model is affected, but `getCastInsts()` also directly affects code generation.

It seems the goal of `getCastInsts()` is generally different from what this patch is trying to do, but I am very interested in any feedback! Depending on that, I will update the patch with steps (2) and (3) identified in the plan.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112549



More information about the llvm-commits mailing list