[PATCH] D90115: [LoopDeletion] Remove dead loops with no exit blocks

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 25 08:58:16 PDT 2020


jdoerfert added a comment.

Logic is sound to me. Some nits below.

Please add a test in which an endless loop w/o exits and w/o side-effects can be replaced with unreachable but the loop has more instructions. So, a phi and some control flow that computes the new phi value.



================
Comment at: llvm/include/llvm/Analysis/LoopInfoImpl.h:143
+  return UniqueExitBlocks.size() == 0;
+}
+
----------------
Nit: `size==0`  => `empty`


================
Comment at: llvm/lib/Transforms/Utils/LoopUtils.cpp:587
+    assert(ExitBlock && "Should have a unique exit block!");
+    assert(L->hasDedicatedExits() && "Loop should have dedicated exits!");
+
----------------
Can't you move ExitBlock into the else branch. Or branch on ExitBlock and assert `hasNoExitBlocks` if it is null? 

Also, do we need to do all the stuff below in the endless case? Could we just return from the then branch? 

Nit: Not sure why you need to set the insert point again.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90115/new/

https://reviews.llvm.org/D90115



More information about the llvm-commits mailing list