[PATCH] D102982: [LoopUnroll] Use smallest exact trip count from any exit

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 26 11:15:08 PDT 2021


reames added a comment.

In D102982#2782674 <https://reviews.llvm.org/D102982#2782674>, @nikic wrote:

> @reames Thanks for the patient explanation and me being so dense. No idea what I was thinking here.
>
> To loop back around to the unrolling use-case, D103182 <https://reviews.llvm.org/D103182> would now provide us with an exact trip count for the loop. However, I think we still need to use the approach from this patch, or something similar to it, for two reasons:
>
> - Without the knowledge //which// exit the trip count is for, we can fold all exits before the TripCount to "not taken", but we don't know which exit is the taken one on the last iteration.

Maybe I'm now being dense, but *why* do we need to know which block was taken?  I'm searching for uses of ExitingBlock in the code, and I can't find it used after the bit of code computing TripCount and TripMultiple.

> - For trip multiples, the "loop trip multiple" would be the minimum of all trip multiples (please correct me if I'm wrong on that!) which I believe is not what is desired for unrolling. If we have one unpredictable exit and one multiple-4 exit, we'd want to unroll against that exit and save use the intermediate branches, but the "loop trip multiple" would be 1 in that case, as we can exit from the loop on every iteration.

So, not minimum of all trip multiples, GCD of the same.  See D103189 <https://reviews.llvm.org/D103189>.

With GCD, I think unrolling gets a huge boost for multiple exit loops.  We can still go further, but we'd need to actual expose multiple multiples to the cost model.  Simply "lying" about the multiple to the costing code seems highly suspect.  (Though, looking at the existing cost modeling code, it looks like it already fudges the multiple.  I have no idea what that code is doing.)

I would request you stage this.  Start with the easy GCD case which is not going to break any assumptions made later in the code (as it is a trip multiple for the loop), then come back to it if you have a motivating example and we can complicate the costing.


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

https://reviews.llvm.org/D102982



More information about the llvm-commits mailing list