summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2014-02-07 00:38:56 +0000
committerManman Ren <manman.ren@gmail.com>2014-02-07 00:38:56 +0000
commitee5625b3c16bb4f0bf73be256c2775246b9acbbb (patch)
tree21b9c7674114d2bf8f5dcd45b17a8e47cf454002
parent1f65cfad962a2f0c27b2dcc2324a76c427ba7e2b (diff)
downloadllvm-ee5625b3c16bb4f0bf73be256c2775246b9acbbb.tar.gz
llvm-ee5625b3c16bb4f0bf73be256c2775246b9acbbb.tar.bz2
llvm-ee5625b3c16bb4f0bf73be256c2775246b9acbbb.tar.xz
PGO branch weight: fix PR18752.
Fix a bug triggered in IfConverterTriangle when CvtBB has multiple predecessors by getting the weights before removing a successor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200958 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/IfConversion.cpp9
-rw-r--r--test/CodeGen/ARM/ifcvt-branch-weight-bug.ll62
2 files changed, 66 insertions, 5 deletions
diff --git a/lib/CodeGen/IfConversion.cpp b/lib/CodeGen/IfConversion.cpp
index f0e8c4775c..b664b3b191 100644
--- a/lib/CodeGen/IfConversion.cpp
+++ b/lib/CodeGen/IfConversion.cpp
@@ -1180,12 +1180,14 @@ bool IfConverter::IfConvertTriangle(BBInfo &BBI, IfcvtKind Kind) {
DontKill.clear();
bool HasEarlyExit = CvtBBI->FalseBB != NULL;
- uint64_t CvtNext = 0, CvtFalse = 0, SumWeight = 0;
+ uint64_t CvtNext = 0, CvtFalse = 0, BBNext = 0, BBCvt = 0, SumWeight = 0;
uint32_t WeightScale = 0;
if (HasEarlyExit) {
- // Get weights before modifying CvtBBI->BB.
+ // Get weights before modifying CvtBBI->BB and BBI.BB.
CvtNext = MBPI->getEdgeWeight(CvtBBI->BB, NextBBI->BB);
CvtFalse = MBPI->getEdgeWeight(CvtBBI->BB, CvtBBI->FalseBB);
+ BBNext = MBPI->getEdgeWeight(BBI.BB, NextBBI->BB);
+ BBCvt = MBPI->getEdgeWeight(BBI.BB, CvtBBI->BB);
SumWeight = MBPI->getSumForBlock(CvtBBI->BB, WeightScale);
}
if (CvtBBI->BB->pred_size() > 1) {
@@ -1222,9 +1224,6 @@ bool IfConverter::IfConvertTriangle(BBInfo &BBI, IfcvtKind Kind) {
// New_Weight(BBI.BB, CvtBBI->FalseBB) =
// Weight(BBI.BB, CvtBBI->BB) * Weight(CvtBBI->BB, CvtBBI->FalseBB)
- uint64_t BBNext = MBPI->getEdgeWeight(BBI.BB, NextBBI->BB);
- uint64_t BBCvt = MBPI->getEdgeWeight(BBI.BB, CvtBBI->BB);
-
uint64_t NewNext = BBNext * SumWeight + (BBCvt * CvtNext) / WeightScale;
uint64_t NewFalse = (BBCvt * CvtFalse) / WeightScale;
// We need to scale down all weights of BBI.BB to fit uint32_t.
diff --git a/test/CodeGen/ARM/ifcvt-branch-weight-bug.ll b/test/CodeGen/ARM/ifcvt-branch-weight-bug.ll
new file mode 100644
index 0000000000..86ed5b22b6
--- /dev/null
+++ b/test/CodeGen/ARM/ifcvt-branch-weight-bug.ll
@@ -0,0 +1,62 @@
+; RUN: llc < %s -mtriple=armv4t--linux-androideabi -print-machineinstrs=if-converter -o /dev/null 2>&1 | FileCheck %s
+; Fix a bug triggered in IfConverterTriangle when CvtBB has multiple
+; predecessors.
+; PR18752
+
+%classK = type { i8, %classF }
+%classF = type { i8 }
+%classL = type { %classG, i32, i32 }
+%classG = type { %classL* }
+%classM2 = type { %classL }
+
+define zeroext i1 @test(%classK* %this, %classM2* nocapture readnone %p1, %classM2* nocapture readnone %p2) align 2 {
+entry:
+ br i1 undef, label %for.end, label %for.body
+
+; Before if conversion, we have
+; for.body -> lor.lhs.false.i (62)
+; -> for.cond.backedge (62)
+; lor.lhs.false.i -> for.cond.backedge (1048575)
+; -> cond.false.i (1)
+; Afer if conversion, we have
+; for.body -> for.cond.backedge (130023362)
+; -> cond.false.i (62)
+; CHECK: BB#1: derived from LLVM BB %for.body
+; CHECK: Successors according to CFG: BB#2(130023362) BB#4(62)
+for.body:
+ br i1 undef, label %for.cond.backedge, label %lor.lhs.false.i
+
+for.cond.backedge:
+ %tobool = icmp eq %classL* undef, null
+ br i1 %tobool, label %for.end, label %for.body
+
+lor.lhs.false.i:
+ %tobool.i.i7 = icmp eq i32 undef, 0
+ br i1 %tobool.i.i7, label %for.cond.backedge, label %cond.false.i
+
+cond.false.i:
+ call void @_Z3fn1v()
+ unreachable
+
+for.end:
+ br i1 undef, label %if.else.i.i, label %if.then.i.i
+
+if.then.i.i:
+ store %classL* null, %classL** undef, align 4
+ br label %_ZN1M6spliceEv.exit
+
+if.else.i.i:
+ store %classL* null, %classL** null, align 4
+ br label %_ZN1M6spliceEv.exit
+
+_ZN1M6spliceEv.exit:
+ %LIS = getelementptr inbounds %classK* %this, i32 0, i32 1
+ call void @_ZN1F10handleMoveEb(%classF* %LIS, i1 zeroext false)
+ unreachable
+}
+
+declare %classL* @_ZN1M1JI1LS1_EcvPS1_Ev(%classM2*)
+declare void @_ZN1F10handleMoveEb(%classF*, i1 zeroext)
+declare void @_Z3fn1v()
+
+!0 = metadata !{metadata !"clang version 3.5"}