[PATCH] D44818: [LoopUnroll] Fix dangling pointers in SCEV

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 22:38:30 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: greened, davide, samparker, sanjoy, anna, reames.

Current logic of loop SCEV invalidation in Loop Unroller implicitly relies on
fact that exit count of outer loops cannot rely on exiting blocks of
inner loops, which is true in current implementation of backedge taken count
calculation but is wrong in general. As result, when we only forget the loop that
we have just unrolled, we may still have cached data for its outer loops (in particular,
exit counts) which keeps references on blocks of inner loop that could have been
changed or even deleted.

The attached test demonstrates a situaton when after unrolling of innermost loop
the outermost loop contains a dangling pointer on non-existant block. The problem
shows up when we apply patch https://reviews.llvm.org/D44677 that makes SCEV
smarter about exit count calculation. I am not sure if the bug exists without this patch,
it appears that now it is accidentally correct just because in practice exact backedge
taken count for outer loops with complex control flow inside is never calculated.
But when SCEV learns to do so, this problem shows up.

This patch replaces existing logic of SCEV loop invalidation with a correct one, which
happens to be invalidation of outermost loop (which also leads to invalidation of all
loops inside of it). It is the only way to ensure that no outer loop keeps dangling pointers
on removed blocks, or just outdated information that has changed after unrolling.


https://reviews.llvm.org/D44818

Files:
  lib/Transforms/Utils/LoopUnroll.cpp
  test/Transforms/LoopUnroll/invalidate_right_loop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44818.139560.patch
Type: text/x-patch
Size: 6322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180323/17b3f4b7/attachment.bin>


More information about the llvm-commits mailing list