[PATCH] D32494: [Loop Deletion] Delete loops that are semantically unreachable
Anna Thomas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 09:27:25 PDT 2017
anna added inline comments.
================
Comment at: lib/Transforms/Scalar/LoopDeletion.cpp:279
+ // We set it to the undef value instead of removing the incoming value to
+ // avoid dealing with dead phi's, which may make the corresponding block
+ // dead.
----------------
anna wrote:
> sanjoy wrote:
> > How do dead phis make a block dead?
> >
> > If you're talking about keeping the edge from SourceBB to ExitBlock even though it will never be taken, then I see what you mean, but that comment should be on `SourceBB->getTerminator()->replaceUsesOfWith(L->getHeader(), ExitBlock);`. Btw, what is the problem with deleting that edge? Is it with updating LoopInfo or something else?
> >
> This comment is incorrect. There's no problem in deleting the edge. The only reason is to keep the code here similar in both cases: keep the edge from the source block to the exit block. If I special case the "loop never executes" scenario to delete the edge, we can remove the value from the phi as well.
> For now, I'll keep the code the same, and leave the edge as-is.
just FYI, it looks like there is a problem in deleting the edge. If this loop is within a parent loop, we may break the parent loop's structure.
Consider:
```
L1:
br i1 true, label %exit, label %L2
L2:
br i1 %cond, label %L2, label %L1
```
Here we can delete L2. If we remove the edge from the sourceBlock L1 to the exit block (which will be L1.exit or L1), the loop structure of L1 is no longer preserved. I have added a test case (see test8) in the updated diff, and updated the comment as well.
In test8, both the loops are deleted through iterative calls to loop deletion starting from inner loop to outer loop.
https://reviews.llvm.org/D32494
More information about the llvm-commits
mailing list