[PATCH] D53865: [LoopVectorizer] Improve computation of scalarization overhead.

Hideki Saito via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 13:27:23 PST 2018


hsaito added a comment.

In D53865#1328113 <https://reviews.llvm.org/D53865#1328113>, @jonpa wrote:

> > I think you are either 1) arm-twisting the vectorizer to emit vector code which you know will be scalar or 2) arm-twisting vectorizer's cost model to believe what you are emitting as "vector" to be really scalar. I certainly do not see the reason why "you have to" do that, because letting vectorizer emit scalar IR instructions in those cases should be "equivalent". So, why "do you WANT to" do that? IR going out of vectorizer may be more compact, but what that'll accomplish is cheating all downstream optimizers and their cost models.
>
> I am just trying to keep it simple by not changing how LV generates code, but merely improve the cost computations. Changing the output of a vectorized loop seems like a much bigger project, which I did not attempt.


In my perspective, that's not simple at all. LV already has a mechanism to scalarize instructions, and ways to compute cost for those scalarized instructions. If everyone keeps adding their own way of scalarizing (or computing the cost for it), that's adding unnecessary complexity.

Please try to see if you can add TTI based "can vectorize instruction" check inside this function. Consider something like isScalarWithoutPredication() analogous to isScalarWithPredication().

  void LoopVectorizationCostModel::collectInstsToScalarize(unsigned VF)

Once the instruction is added to InstsToScalarize, the rest of the cost model you desire should just happen --- else, that's where you'd like to contribute to benefit all including you.

Then, go look at the Recipe construction. Again, we need to check similar to isScalarWithPredication and return false here.

  bool VPRecipeBuilder::tryToWiden(Instruction *I, VPBasicBlock *VPBB, VFRange &Range)

That should force the creation of replicate recipe.

Hopefully, that's all you need to do to serialize those vector FP operations for which you don't have HW vector support.


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

https://reviews.llvm.org/D53865





More information about the llvm-commits mailing list