This is an archive of the discontinued LLVM Phabricator instance.

[GuardWidening] Use BFI to reject obviously unprofitable widening
Needs ReviewPublic

Authored by mkazantsev on Mar 28 2023, 2:37 AM.

Details

Summary

Existing profitability model in guard widening is naive. In particular, it assumes
that whenever we can widen the guard away from the loop, we should do it, even
if the loop is never entered. As result, we can end up with conditions widened from
cold (sometimes dynamically dead) code into hot code.

This patch reject grossly unprofitable cases of this using BFI. The heuristic is "if the
destination is at least 2x hotter than the source, reject".

Diff Detail

Event Timeline

mkazantsev created this revision.Mar 28 2023, 2:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 2:37 AM
mkazantsev requested review of this revision.Mar 28 2023, 2:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 2:37 AM

Looks pretty straightforward. Please introduce an option and lgtm.
Any reason you shoose "twice"?

llvm/lib/Transforms/Scalar/GuardWidening.cpp
434

could you please introduce an option?

anna added a comment.Apr 14 2023, 6:09 AM

Looks pretty straightforward. Please introduce an option and lgtm.

+1 on the option. It's nice to have profitability heuristics under an option so that we can stress test functionality.