The motivation is need to update branch probability info after
swapping successors of branch instruction
Details
Diff Detail
Unit Tests
Event Timeline
You could add a unit test here: https://github.com/llvm/llvm-project/blob/main/llvm/unittests/Analysis/BranchProbabilityInfoTest.cpp
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? |
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
This is a layering violation: IR cannot depend on Analysis.
Got it, thanks! Returned previous version
Why do you need this, exactly? I see that swapSuccessors is already updating the metadata:
Is analysis returning invalid result after that?