[all-commits] [llvm/llvm-project] 6c99e6: [SCEV] By more careful when traversing phis in isI...
Florian Hahn via All-commits
all-commits at lists.llvm.org
Fri May 7 11:53:15 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6c99e631201aaea0a75708749cbaf2ba08a493f9
https://github.com/llvm/llvm-project/commit/6c99e631201aaea0a75708749cbaf2ba08a493f9
Author: Florian Hahn <flo at fhahn.com>
Date: 2021-05-07 (Fri, 07 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
More information about the All-commits
mailing list