[PATCH] D151052: [LoopUnroll] Peel iterations based on select conditions

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 20:30:05 PDT 2023


caojoshua marked an inline comment as done.
caojoshua added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/LoopPeel.cpp:352
+    MaxPeelCount =
+        std::min((unsigned)SC->getAPInt().getZExtValue() - 1, MaxPeelCount);
+
----------------
nikic wrote:
> The getZExtValue() here can assert if we the BECount is larger than 64 bits. You can use getLimitedValue() instead.
> 
> > When peeling only branch instructions, we avoid this by ignoring the branch condition of the latch block. But with this patch, we don't ignore and/or's that are used by the latch branch.
> 
> FWIW, I think that's a problem in your and/or handling: You shouldn't pick up random and/ors, but only those rooted at a br or select.
> 
> But anyway, I don't mind adding the check.
Thanks, using `getLimitedValue()` in newest changes. I added a test for peeling large loops BECounts (>2^64) to precommit tests locally.

> FWIW, I think that's a problem in your and/or handling: You shouldn't pick up random and/ors, but only those rooted at a br or select.

Benefit of checking random and/ors is that allows peeling nested and/ors easily. We can also peel for and/ors not used in branches/selects, for example, we might pass a boolean to a function (probably rare in practice though).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151052



More information about the llvm-commits mailing list