[PATCH] D67764: [LV] Runtime checks with OptForSize

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 15:07:19 PDT 2019


SjoerdMeijer added a comment.

Ah, I had completely missed that this is about the interaction of `OptForSize` and the `loop.vectorize` loop hint!
Vectorization is forced, which means that we vectorize even though `OptForSize` is set and we need to emit runtime checks.

The symptom is that we run in this assert in `emitMemRuntimeChecks()`:

  assert(!BB->getParent()->hasOptSize() &&
       "Cannot emit memory checks when optimizing for size");

In `getScalarEpilogueLowering()`, we do **not** set CM_ScalarEpilogueNotAllowedOptSize because of the loop hint:

  if (Hints.getForce() != LoopVectorizeHints::FK_Enabled &&
      (F->hasOptSize() ||
       llvm::shouldOptimizeForSize(L->getHeader(), PSI, BFI))) {
    SEL = CM_ScalarEpilogueNotAllowedOptSize;

And because `CM_ScalarEpilogueNotAllowedOptSize` is not set, we do not check `runtimeChecksRequired`,  so that we end up with code growth under OptForSize because of the loop hint.

If we agree that this is desired behaviour, which looks reasonable to me because of this condition, I am going to remove the assert as that is not valid.


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

https://reviews.llvm.org/D67764





More information about the llvm-commits mailing list