[PATCH] D69617: [LoopUnroll] countToEliminateCompares(): fix handling of [in]equality predicates (PR43840)

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 02:15:24 PST 2019


fhahn added a comment.

> I'm not really sure how that would look, if we look at -loop-unroll -O3
>  for those tests, said loops no longer have that condition anyway.
>  And if we do peel off one more iteration regardless, then we bloat
>  the code by performing one loop iteration outside of the loop,
>  without simplifying the loop.

The interesting test cases for the FIXME are test7 and test8. In those cases, we have to peel off 4 iterations, to eliminate the condition in the loop, but with the current logic we peel off only 3: we currently try to peel until a condition in the loop becomes known. For monotonic predicates, we know it will stay known for the rest of the loop (and can be eliminated further down the road).

For EQ/NE that's not the case. In some cases (like in the tests), it is enough to peel one additional iteration, if the predicate becomes known for the rest of the loop. I think the reason why the conditions in test7 and test8 get eliminated with `-loop-unroll -O3` is that they will get peeled twice. It would also be good to add an additional test cases with NE/EQ predicates that alternate (e.g. a check that the induction variable is even/odd). For such loops, peeling of the first iteration is not really helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69617





More information about the llvm-commits mailing list