[all-commits] [llvm/llvm-project] 0ef783: [IndVarSimplify] Add additional tests using isImpl...

Florian Hahn via All-commits all-commits at lists.llvm.org
Tue May 11 20:53:45 PDT 2021


  Branch: refs/heads/release/12.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 0ef78361565a861cac846b7c1f807dc2d278145d
      https://github.com/llvm/llvm-project/commit/0ef78361565a861cac846b7c1f807dc2d278145d
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2021-05-11 (Tue, 11 May 2021)

  Changed paths:
    M llvm/test/Transforms/IndVarSimplify/eliminate-exit.ll
    M llvm/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll

  Log Message:
  -----------
  [IndVarSimplify] Add additional tests using isImpliedViaMerge.

(cherry picked from commit d65e5f60f110046898ad146c508a7d225d398549)


  Commit: 4e46ff469405bc73ec25fcf78126fb5fbd7a18a1
      https://github.com/llvm/llvm-project/commit/4e46ff469405bc73ec25fcf78126fb5fbd7a18a1
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2021-05-11 (Tue, 11 May 2021)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Transforms/IRCE/decrementing-loop.ll
    M llvm/test/Transforms/IndVarSimplify/eliminate-exit.ll

  Log Message:
  -----------
  [SCEV] By more careful when traversing phis in isImpliedViaMerge.

I think currently isImpliedViaMerge can incorrectly return true for phis
in a loop/cycle, if the found condition involves the previous value of

Consider the case in exit_cond_depends_on_inner_loop.

At some point, we call (modulo simplifications)
isImpliedViaMerge(<=, %x.lcssa, -1, %call, -1).

The existing code tries to prove IncV <= -1 for all incoming values
InvV using the found condition (%call <= -1). At the moment this succeeds,
but only because it does not compare the same runtime value. The found
condition checks the value of the last iteration, but the incoming value
is from the *previous* iteration.

Hence we incorrectly determine that the *previous* value was <= -1,
which may not be true.

I think we need to be more careful when looking at the incoming values
here. In particular, we need to rule out that a found condition refers to
any value that may refer to one of the previous iterations. I'm not sure
there's a reliable way to do so (that also works of irreducible control
flow).

So for now this patch adds an additional requirement that the incoming
value must properly dominate the phi block. This should ensure the
values do not change in a cycle. I am not entirely sure if will catch
all cases and I appreciate a through second look in that regard.

Alternatively we could also unconditionally bail out in this case,
instead of checking the incoming values

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D101829

(cherry picked from commit 6c99e631201aaea0a75708749cbaf2ba08a493f9)


Compare: https://github.com/llvm/llvm-project/compare/6912082cfd12...4e46ff469405


More information about the All-commits mailing list