This is an archive of the discontinued LLVM Phabricator instance.

[LoopPeel] Allow to bypass profitability checks. NFC
AbandonedPublic

Authored by anna on Oct 6 2022, 11:57 AM.

Details

Reviewers
fhahn
skatkov
Summary

canPeel API checks legality as well as profitability of peeling the
loop. Separate this out since sometimes (for example downstream), we
just need to know if we can peel the loop.

Currently, since we have exactly one profitability check, it seems
unnecessary to have a separate API for this. So, we just decide based on
the passed in argument.
This is an NFC, since by default we always check profitability.

Diff Detail

Event Timeline

anna created this revision.Oct 6 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 11:57 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
anna requested review of this revision.Oct 6 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 11:57 AM
nikic added a subscriber: nikic.Oct 6 2022, 12:11 PM

As the comment indicates, this is not entirely a profitability check: The current peeling code does not correctly update branch weights if this condition is not satisfied. D134803 implements the necessary support and removes this check entirely.

I also don't get how you plan to use this flag -- after all peelLoop() also contains a canPeel() assertion, so you wouldn't be able to call to call it anyway.

anna added a comment.EditedOct 6 2022, 1:07 PM

As the comment indicates, this is not entirely a profitability check: The current peeling code does not correctly update branch weights if this condition is not satisfied. D134803 implements the necessary support and removes this check entirely.

Ah, I only saw the need for the profitability check. Note that we still needed the profitability check downstream (the comment just piggybacked on the fact that there was missing functionality) so removing it entirely in D134803 would break performance for us. We are using canPeel in more cases (java optimizations) than here in upstream code.

I also don't get how you plan to use this flag -- after all peelLoop() also contains a canPeel() assertion, so you wouldn't be able to call to call it anyway.

Yes, that's right. I didn't see the canPeel assertion. I just had a separate API downstream for profitability. I think it makes sense to introduce the profitability API as such upstream and separate out the legality from profitability.

nikic added a comment.Oct 6 2022, 1:21 PM

I don't think there is a single "profitability" API for loop peeling. Loop peeling currently performs three different types of peeling: To render conditions invariant, to make loads dereferenceable and to peel based on PGO loop count. These have different profitability criterions. The current (in-tree) implementation already separately checks profitability for these cases (with the first case being essentially always profitable, and the other two using the deopt/unreachable exit check, plus additional profitability checks). I believe the check in canPeel() itself is only relevant for the branch weight issues at this point, profitability is handled separately on a case-by-case basis. If you have out-of-tree uses of loop peeling, you likely want to do the same there.

anna abandoned this revision.Oct 7 2022, 8:24 AM

agreed. abandoning the change in favour of D134803. We will add the profitability check downstream for the case we need. Thanks.