[PATCH] D91325: [IndVarSimplify] Drop any stored trip count value before IndVarSimplify
guopeilin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 00:49:11 PST 2020
guopeilin added a comment.
In D91325#2392962 <https://reviews.llvm.org/D91325#2392962>, @mkazantsev wrote:
> I'm not really getting how wrong cached exit count may possibly lead to hang. Could you please explain this problem more?
>From the cfg we can see that there exist a nested loop, and basic block `if.then` is a shared exitingBB between inner and outer loop.
When we start running IndVarSimplify pass on the inner loop, we can get block `if.then`'s `ExitCount` by function `ScalarEvolution::getExitCount()`, also we can get inner loop's `MaxExitCount` by function `getMaxBackedgeTakenCount`.
If a exitingBB's exit count less than loop's max backedge taken count, we can say that this loop never exit from this exitingBB. So we can `FoldExit`, that is we replace the condition of exitingBB's BranchInst with a ConstantInt. So after we done IndVarSimplify pass on the inner loop, the `if.the` will be simplified into a uncondtional block.
However, when we begin running IndVarSimplify on outer loop, `if.then` also is outer loop's exitingBB, and we don't know it has been simplified. So we will get the cached exit count (which is totally wrong), this count is used for compute `MaxBackedgeTakenCount` of outer loop.
Unfortunately this `MaxBackedgeTakenCount` is less than block `for.inc15`'s exit count. So IndVarSimplify think outer loop never exit in `for.inc15`, we can then fold this exitingBB, finally make outer loop endless.
Before IndVarSimplify
=====================
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91325/new/
https://reviews.llvm.org/D91325
More information about the llvm-commits
mailing list