[llvm] r269137 - Propagate branch metadata when some branch probability is missing.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue May 10 16:07:20 PDT 2016
Author: dehao
Date: Tue May 10 18:07:19 2016
New Revision: 269137
URL: http://llvm.org/viewvc/llvm-project?rev=269137&view=rev
Log:
Propagate branch metadata when some branch probability is missing.
Summary: In sample profile, some branches may have profile missing due to profile inaccuracy. We want existing branch probability still valid after propagation.
Reviewers: hfinkel, davidxl, spatel
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D19948
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=269137&r1=269136&r2=269137&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue May 10 18:07:19 2016
@@ -2821,15 +2821,23 @@ static bool SimplifyCondBranchToCondBran
// Update branch weight for PBI.
uint64_t PredTrueWeight, PredFalseWeight, SuccTrueWeight, SuccFalseWeight;
+ uint64_t PredCommon, PredOther, SuccCommon, SuccOther;
bool PredHasWeights =
PBI->extractProfMetadata(PredTrueWeight, PredFalseWeight);
bool SuccHasWeights =
BI->extractProfMetadata(SuccTrueWeight, SuccFalseWeight);
- if (PredHasWeights && SuccHasWeights) {
- uint64_t PredCommon = PBIOp ? PredFalseWeight : PredTrueWeight;
- uint64_t PredOther = PBIOp ?PredTrueWeight : PredFalseWeight;
- uint64_t SuccCommon = BIOp ? SuccFalseWeight : SuccTrueWeight;
- uint64_t SuccOther = BIOp ? SuccTrueWeight : SuccFalseWeight;
+ bool HasWeights = PredHasWeights || SuccHasWeights;
+ if (HasWeights) {
+ if (!PredHasWeights) {
+ PredFalseWeight = PredTrueWeight = 1;
+ }
+ if (!SuccHasWeights) {
+ SuccFalseWeight = SuccTrueWeight = 1;
+ }
+ PredCommon = PBIOp ? PredFalseWeight : PredTrueWeight;
+ PredOther = PBIOp ? PredTrueWeight : PredFalseWeight;
+ SuccCommon = BIOp ? SuccFalseWeight : SuccTrueWeight;
+ SuccOther = BIOp ? SuccTrueWeight : SuccFalseWeight;
// The weight to CommonDest should be PredCommon * SuccTotal +
// PredOther * SuccCommon.
// The weight to OtherDest should be PredOther * SuccOther.
Modified: llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll?rev=269137&r1=269136&r2=269137&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll Tue May 10 18:07:19 2016
@@ -464,6 +464,30 @@ exit:
ret i32 %outval
}
+define i32 @SimplifyCondBranchToCondBranchSwapMissingWeight(i1 %cmpa, i1 %cmpb) {
+; CHECK-LABEL: @SimplifyCondBranchToCondBranchSwapMissingWeight(
+; CHECK-NEXT: block1:
+; CHECK-NEXT: [[CMPA_NOT:%.*]] = xor i1 %cmpa, true
+; CHECK-NEXT: [[CMPB_NOT:%.*]] = xor i1 %cmpb, true
+; CHECK-NEXT: [[BRMERGE:%.*]] = or i1 [[CMPA_NOT]], [[CMPB_NOT]]
+; CHECK-NEXT: [[DOTMUX:%.*]] = select i1 [[CMPA_NOT]], i32 0, i32 2
+; CHECK-NEXT: [[OUTVAL:%.*]] = select i1 [[BRMERGE]], i32 [[DOTMUX]], i32 1, !prof !16
+; CHECK-NEXT: ret i32 [[OUTVAL]]
+;
+block1:
+ br i1 %cmpa, label %block2, label %block3, !prof !13
+
+block2:
+ br i1 %cmpb, label %exit, label %block3
+
+block3:
+ %cowval = phi i32 [ 2, %block2 ], [ 0, %block1 ]
+ br label %exit
+
+exit:
+ %outval = phi i32 [ %cowval, %block3 ], [ 1, %block2 ]
+ ret i32 %outval
+}
!0 = !{!"branch_weights", i32 3, i32 5}
!1 = !{!"branch_weights", i32 1, i32 1}
@@ -499,4 +523,4 @@ exit:
; CHECK: !13 = !{!"branch_weights", i32 34, i32 21}
; CHECK: !14 = !{!"branch_weights", i32 33, i32 14}
; CHECK: !15 = !{!"branch_weights", i32 47, i32 8}
-
+; CHECK: !16 = !{!"branch_weights", i32 8, i32 2}
More information about the llvm-commits
mailing list