[PATCH] D125754: [LoopUnroll] Avoid branch on poison for runtime unroll with multiple exits

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 17 08:40:48 PDT 2022


reames accepted this revision.
reames added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp:755
   BasicBlock *UnrollingLoop = UseEpilogRemainder ? NewPreHeader : PrologExit;
+  // Freeze the condition if there are other exits before the latch that may
+  // cause the latch exit branch to never be executed.
----------------
nikic wrote:
> reames wrote:
> > Its not clear to me that you need this.  The condition being branched on should always be derived from the SCEV computed trip count.  After D124910, shouldn't we be assured that is non-poisonous?  Or at least, only poisonous if the first input is poison?  
> > 
> > Your code here is completely reasonable, except that I don't quite understand the case in which is matters.  :)
> Runtime loop unrolling doesn't use the backedge taken count (which is what D124910 is about), it works only on the latch exit count. So if you have two exits at `n` and `m` (with `m` being the latch exit), runtime unroll will unroll using `m`, not `umin(n, m)`. That's why we need to handle this explicitly, it wouldn't be going through the umin_seq code.
You are correct.  Odd, I thought we'd changed that previously, but it looks like we haven't.  


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

https://reviews.llvm.org/D125754



More information about the llvm-commits mailing list