[PATCH] D32494: [Loop Deletion] Delete loops that are never executed

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 15:04:56 PDT 2017


sanjoy added inline comments.


================
Comment at: lib/Transforms/Scalar/LoopDeletion.cpp:188
+  // backedge, and all statements in the loop are invariant. This is a non-loop
+  // if we can move all statements within the loop to the preheader.
+  // We can only remove the loop if there is a preheader that we can
----------------
anna wrote:
> sanjoy wrote:
> > I didn't understand the "has no backedge" part -- if it does not have a backedge how is it a loop?
> Actually, what I meant was it's "semantically not having a backedge": in `isLoopDead`, we check to see that only invariant values from the loop are used in the exit block. Then we hoist these invariant values *and their operands* to the preheader. I think this is equivalent to "semantically not having a backedge". I'm just going to remove these comments instead of going into all this detail :)
> 
> But just for my own clarification, do you think equivalent, or my statement is a stronger version of `isLoopDead`? 
> But just for my own clarification, do you think equivalent, or my statement is a stronger version of isLoopDead?

I believe the code is checking for loops like this:

```
int x = ..., y = ...;
int z;
for (int i = 0; i < 5; i++)
  z = x + y;
use(z);
```

I'd say the loop above does have a backedge but you're right in pointing out that the backedge is not "useful".



https://reviews.llvm.org/D32494





More information about the llvm-commits mailing list