[all-commits] [llvm/llvm-project] 602916: [IndVars] Apply more optimistic SkipLastIter for A...

Max Kazantsev via All-commits all-commits at lists.llvm.org
Mon Jan 23 21:45:29 PST 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 602916d2defa95cf4bec76e458be4375dbe70e4a
  Author: Max Kazantsev <mkazantsev at azul.com>
  Date:   2023-01-24 (Tue, 24 Jan 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
    M llvm/test/Transforms/IndVarSimplify/X86/widening-vs-and-elimination.ll
    M llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll

  Log Message:
  [IndVars] Apply more optimistic SkipLastIter for AND/OR conditions

When exit by condition `C1` dominates exit by condition `C2`, and
max symbolic exit count for `C1` matches those for loop, we will
apply more optimistic logic to `C2` by setting `SkipLastIter` for it,
meaning that it will do 1 iteration less because the dominating branch
must exit on the last loop iteration.

But when we have a single exit by condition `C1 & C2`, we cannot
apply the same logic, because there is no dominating condition.

However, if we can prove that the symbolic max exit count of `C1 & C2`
matches those of `C1`, it means that for `C2` we can assume that it
doesn't matter on the last iteration (because the whole thing is `false`
because `C1` must be `false`). Therefore, in this situation, we can handle
`C2` as if it had `SkipLastIter`.

Differential Revision: https://reviews.llvm.org/D139934
Reviewed By: nikic

More information about the All-commits mailing list