[PATCH] D19674: [SimplifyCFG] propagate branch metadata when creating select

David Li via llvm-commits llvm-commits at lists.llvm.org
Sun May 1 23:23:50 PDT 2016


davidxl added inline comments.

================
Comment at: test/Transforms/SimplifyCFG/preserve-branchweights.ll:422
@@ -421,3 +421,3 @@
 ; CHECK-NEXT:    [[BRMERGE:%.*]] = or i1 %cmpb, %cmpa
-; CHECK-NEXT:    [[DOTMUX:%.*]] = select i1 %cmpb, i32 0, i32 2
+; CHECK-NEXT:    [[DOTMUX:%.*]] = select i1 %cmpb, i32 0, i32 2, !prof !11
 ; CHECK-NEXT:    [[OUTVAL:%.*]] = select i1 [[BRMERGE]], i32 [[DOTMUX]], i32 1, !prof !12
----------------
spatel wrote:
> davidxl wrote:
> > spatel wrote:
> > > davidxl wrote:
> > > > If I read the code correctly, should the weights for select be 9:5 ? !11 does not look correct.
> > > I thought the weights for the select would be equal to the weights of the original branch because they have the same comparison condition (%cmpb), 3:5. How do you calculate 9:5?
> > Should it be 3 : 5 * (1/3)  which 9 : 5?  When block 2 is entered, there is only 1/3 probability it reaches block3.
> Aha - yes. Although it's the same comparison operand, we have changed the program structure - we are speculatively executing the select, so the original branch weights no longer apply.
> 
> This brings up my question from the original summary then - do you know if there's a reason not to use the BranchProbability class for calculating the new weights? 
> 
BPI provides general APIs to access/read branch probability information that is either from profile data, or from static branch prediction.  

Here the transformation just needs to update the profile data, using low level meta data interfaces is fine (Besides BPI does not have  complete  update APIs either).


http://reviews.llvm.org/D19674





More information about the llvm-commits mailing list