[llvm] [LoopPeel] Allow bidirection condition change for last iteration peeling (PR #143562)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 10:13:21 PDT 2025
preames wrote:
> There's a possible concern here - the condition doesn't appear to be being discharged in the main loop after peeling. I can't find anything which seems specific to the inverted predicate, so I think this is an existing issue for any reverse peeling, but am I missing something?
I looked at this a bit deeper, and realized we do have a general profitability issue here. The equality conditions allowed (in addition to the monotonic relative compares) can toggle more than once. (Consider <0,+,1> == 3 when BTC == 8 - this will be false, then true, then false.) I think the code was written thinking of conditions which control loop exits which dominate the latch - in which case the conditions would toggle at most once.
I don't believe this is unsound, but it will produce unprofitable peelings (both forward and backward) as the condition we think is going to be discharged by peeling isn't actually invariant in the remaining loop!
This isn't specific to this patch at all, though I should probably find a test case which is actually profitable. :)
https://github.com/llvm/llvm-project/pull/143562
More information about the llvm-commits
mailing list