[llvm] [SimplifyCFG] Not folding branch in loop header with constant iterations (PR #74268)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 02:06:50 PST 2023


xiangzh1 wrote:

> I checked, and for your test case, LoopUnroll recognizes the loop as an UpperBound unrolling candidate, but does not perform unrolling due to cost model.
> 
> The pragma unroll metadata currently only takes effect if there is an exact trip count, but not if there is an upper bound trip count. Making it work with an upper bound trip count as well should fix your case. See the code in shouldPragmaUnroll().

First, many thanks for checking the test.
Yes, that's another way to unroll too, but it is branch folding affected the cost model, it didn't consider the later unroll. In fact we don't much want to do unroll with UpperBound. Even it unroll successful with UpperBound, it is not better than unrolled with known loop count.  Espically for known small loop count which ususally can be full unrolled, in GPU this is much helpful to symplify address (offset) calculations, which is sensitive in SROA optimization and local mem use.

https://github.com/llvm/llvm-project/pull/74268


More information about the llvm-commits mailing list