[llvm] r297054 - [IfConversion] Only renormalize probabilities if branches are analyzable
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 6 11:12:43 PST 2017
Author: kparzysz
Date: Mon Mar 6 13:12:42 2017
New Revision: 297054
URL: http://llvm.org/viewvc/llvm-project?rev=297054&view=rev
Log:
[IfConversion] Only renormalize probabilities if branches are analyzable
If a block has non-analyzable branches, the listed successors don't need
to add up to one. For example, if a block has a conditional tail call,
that tail call will not have a corresponding successor in the successor
list, but will still be a possible branch.
Differential Revision: https://reviews.llvm.org/D30556
Added:
llvm/trunk/test/CodeGen/Hexagon/ifcvt-simple-bprob.ll
Modified:
llvm/trunk/lib/CodeGen/IfConversion.cpp
Modified: llvm/trunk/lib/CodeGen/IfConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/IfConversion.cpp?rev=297054&r1=297053&r2=297054&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/IfConversion.cpp (original)
+++ llvm/trunk/lib/CodeGen/IfConversion.cpp Mon Mar 6 13:12:42 2017
@@ -2148,7 +2148,8 @@ void IfConverter::MergeBlocks(BBInfo &To
// unknown probabilities into known ones.
// FIXME: This usage is too tricky and in the future we would like to
// eliminate all unknown probabilities in MBB.
- ToBBI.BB->normalizeSuccProbs();
+ if (ToBBI.IsBrAnalyzable)
+ ToBBI.BB->normalizeSuccProbs();
SmallVector<MachineBasicBlock *, 4> FromSuccs(FromMBB.succ_begin(),
FromMBB.succ_end());
@@ -2228,7 +2229,8 @@ void IfConverter::MergeBlocks(BBInfo &To
// Normalize the probabilities of ToBBI.BB's successors with all adjustment
// we've done above.
- ToBBI.BB->normalizeSuccProbs();
+ if (ToBBI.IsBrAnalyzable && FromBBI.IsBrAnalyzable)
+ ToBBI.BB->normalizeSuccProbs();
ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
FromBBI.Predicate.clear();
Added: llvm/trunk/test/CodeGen/Hexagon/ifcvt-simple-bprob.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/ifcvt-simple-bprob.ll?rev=297054&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/ifcvt-simple-bprob.ll (added)
+++ llvm/trunk/test/CodeGen/Hexagon/ifcvt-simple-bprob.ll Mon Mar 6 13:12:42 2017
@@ -0,0 +1,36 @@
+; RUN: llc -march=hexagon < %s
+
+; Check that branch probabilities are set correctly after performing the
+; simple variant of if-conversion. The converted block has a branch that
+; is not analyzable.
+
+target triple = "hexagon"
+
+declare void @foo()
+
+; CHECK-LABEL: danny
+; CHECK: if (p0.new) jump:nt foo
+define void @danny(i32 %x) {
+ %t0 = icmp sgt i32 %x, 0
+ br i1 %t0, label %tail, label %exit, !prof !0
+tail:
+ tail call void @foo();
+ ret void
+exit:
+ ret void
+}
+
+; CHECK-LABEL: sammy
+; CHECK: if (!p0.new) jump:t foo
+define void @sammy(i32 %x) {
+ %t0 = icmp sgt i32 %x, 0
+ br i1 %t0, label %exit, label %tail, !prof !0
+tail:
+ tail call void @foo();
+ ret void
+exit:
+ ret void
+}
+
+!0 = !{!"branch_weights", i32 1, i32 2000}
+
More information about the llvm-commits
mailing list