[llvm] r268935 - [CGP] avoid crashing from weightlessness
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon May 9 10:31:55 PDT 2016
Author: spatel
Date: Mon May 9 12:31:55 2016
New Revision: 268935
URL: http://llvm.org/viewvc/llvm-project?rev=268935&view=rev
Log:
[CGP] avoid crashing from weightlessness
It's possible that we have branch weights with 0 values.
In that case, don't try to create an impossible BranchProbability.
Modified:
llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
llvm/trunk/test/CodeGen/X86/cmov-into-branch.ll
Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=268935&r1=268934&r2=268935&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Mon May 9 12:31:55 2016
@@ -4559,9 +4559,11 @@ static bool isFormingBranchFromSelectPro
if (SI->extractProfMetadata(TrueWeight, FalseWeight)) {
uint64_t Max = std::max(TrueWeight, FalseWeight);
uint64_t Sum = TrueWeight + FalseWeight;
- auto Probability = BranchProbability::getBranchProbability(Max, Sum);
- if (Probability > TLI->getPredictableBranchThreshold())
- return true;
+ if (Sum != 0) {
+ auto Probability = BranchProbability::getBranchProbability(Max, Sum);
+ if (Probability > TLI->getPredictableBranchThreshold())
+ return true;
+ }
}
CmpInst *Cmp = dyn_cast<CmpInst>(SI->getCondition());
Modified: llvm/trunk/test/CodeGen/X86/cmov-into-branch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cmov-into-branch.ll?rev=268935&r1=268934&r2=268935&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cmov-into-branch.ll (original)
+++ llvm/trunk/test/CodeGen/X86/cmov-into-branch.ll Mon May 9 12:31:55 2016
@@ -114,8 +114,22 @@ define i32 @weighted_select3(i32 %a, i32
ret i32 %sel
}
+; Weightlessness is no reason to die.
+define i32 @unweighted_select(i32 %a, i32 %b) {
+; CHECK-LABEL: unweighted_select:
+; CHECK: # BB#0:
+; CHECK-NEXT: testl %edi, %edi
+; CHECK-NEXT: cmovnel %edi, %esi
+; CHECK-NEXT: movl %esi, %eax
+; CHECK-NEXT: retq
+;
+ %cmp = icmp ne i32 %a, 0
+ %sel = select i1 %cmp, i32 %a, i32 %b, !prof !3
+ ret i32 %sel
+}
!0 = !{!"branch_weights", i32 1, i32 99}
!1 = !{!"branch_weights", i32 1, i32 100}
!2 = !{!"branch_weights", i32 100, i32 1}
+!3 = !{!"branch_weights", i32 0, i32 0}
More information about the llvm-commits
mailing list