This is an archive of the discontinued LLVM Phabricator instance.

[BPI] Add method to swap outgoing edges probabilities
ClosedPublic

Authored by aleksandr.popov on Apr 13 2023, 8:18 AM.

Details

Summary

The motivation is need to update branch probability info after
swapping successors of branch instruction

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 8:18 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
aleksandr.popov requested review of this revision.Apr 13 2023, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 8:18 AM
fhahn added a comment.Apr 13 2023, 8:25 AM

Could you also link a the patch that actually makes use of this?

Could you also link a the patch that actually makes use of this?

Sure, https://reviews.llvm.org/D148244

mkazantsev added inline comments.Apr 13 2023, 10:10 PM
llvm/lib/Analysis/BranchProbabilityInfo.cpp
1184

Why do you need this, exactly? I see that swapSuccessors is already updating the metadata:

void BranchInst::swapSuccessors() {
  assert(isConditional() &&
         "Cannot swap successors of an unconditional branch");
  Op<-1>().swap(Op<-2>());

  // Update profile metadata if present and it matches our structural
  // expectations.
  swapProfMetadata();
}

Is analysis returning invalid result after that?

mkazantsev added inline comments.Apr 13 2023, 10:15 PM
llvm/lib/Analysis/BranchProbabilityInfo.cpp
1184

Yeah, seems it doesn't. Why don't we just add BPI an optional parameter to swapSuccessors and make this update there in this case?

Yes, good point, I've move update into swapSuccessors.
But do you suggest to use existing set/getEdgeProbability to swap BPI or to add this new method swapSuccEdgesProbabilities?

I think we should add a parameter to existing method. There are already precedents of that, e.g. SplitBlock at https://llvm.org/doxygen/BasicBlockUtils_8h.html

nikic requested changes to this revision.Apr 18 2023, 2:25 AM

This is a layering violation: IR cannot depend on Analysis.

This revision now requires changes to proceed.Apr 18 2023, 2:25 AM

This is a layering violation: IR cannot depend on Analysis.

Got it, thanks! Returned previous version

nikic accepted this revision.Apr 18 2023, 3:16 AM

Looks reasonable to me.

This revision is now accepted and ready to land.Apr 18 2023, 3:16 AM
This revision was landed with ongoing or failed builds.Apr 18 2023, 6:05 AM
This revision was automatically updated to reflect the committed changes.