This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Discard stale prof branch_weights for partial unswitched branches
Needs RevisionPublic

Authored by yrouban on Apr 16 2019, 4:30 AM.

Details

Summary

In https://reviews.llvm.org/D60606#1464782 Philip Reames pointed out that partial unswitched branches lose their profile information.
This patch fixes SimpleLoopUnswitch pass to make it happen: to not reuse the stale perf branch_weights if any but explicitly discard them for partially unswitched branches.
Couple of tests are fixed to check the changes both for trivial and non-trivial unswitch.

Diff Detail

Event Timeline

yrouban created this revision.Apr 16 2019, 4:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2019, 4:30 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
reames requested changes to this revision.Apr 22 2019, 3:05 PM

The change description and your tests make it hard to determine what your intended result is. Please fix.

Please update your change description to explain *why* stripping metadata is the best answer. A small example might help. Or alternatively, turn the small examples into (new) test cases and reference them from the proposed commit message.

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
490

I believe the same problem exists for full unswitch as well, and thus this change should not be conditional.

As an example, consider:
loop {

if (A) break
if (B) break;

}

Where we're unswitching B, but not A for some reason. The frequency on the new B branch could be quite different depending on whether A and B are correlated.

2013

I'd suggest moving this to right after the branch successor rewriting.

Also, there is a bug here if this function is called w/BI null and SI non null.

llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
2703

Please separate and commit your test changes, then rebase over them. At the moment, I can't actually tell what's changing vs what are changes to the tests.

note that you should make sure to have tests both with and without profile weights. You don't need to (and should not) fully duplicate, but at least a few of each are required.

This revision now requires changes to proceed.Apr 22 2019, 3:05 PM