From ec26641b79305304fcb6d5f0d3091797695843ed Mon Sep 17 00:00:00 2001 From: John Brawn Date: Wed, 12 Jul 2017 13:23:10 +0000 Subject: [PATCH] [ARM] Adjust ifcvt heuristic for the diamond ifcvt case When we have a diamond ifcvt the fallthough block will have a branch at the end of it that disappears when predicated, so discount it from the predication cost. Differential Revision: https://reviews.llvm.org/D34952 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307788 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMBaseInstrInfo.cpp | 3 +++ .../Thumb2/ifcvt-no-branch-predictor.ll | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Target/ARM/ARMBaseInstrInfo.cpp b/lib/Target/ARM/ARMBaseInstrInfo.cpp index 1ec6b24b2ed..3cf5950a191 100644 --- a/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -1880,6 +1880,9 @@ isProfitableToIfCvt(MachineBasicBlock &TBB, // Diamond: TBB is the block that is branched to, FBB is the fallthrough TUnpredCycles = TCycles + TakenBranchCost; FUnpredCycles = FCycles + NotTakenBranchCost; + // The branch at the end of FBB will disappear when it's predicated, so + // discount it from PredCost. + PredCost -= 1 * ScalingUpFactor; } // The total cost is the cost of each path scaled by their probabilites unsigned TUnpredCost = Probability.scale(TUnpredCycles * ScalingUpFactor); diff --git a/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll b/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll index 9fcc0f5d617..5c3800e9709 100644 --- a/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll +++ b/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll @@ -95,15 +95,17 @@ if.end: } ; CHECK-LABEL: diamond2: -; CHECK-BP: itte -; CHECK-BP: streq -; CHECK-BP: ldreq -; CHECK-BP: strne -; CHECK-NOBP: cbz -; CHECK-NOBP: str -; CHECK-NOBP: b -; CHECK-NOBP: str -; CHECK-NOBP: ldr +; CHECK-BP: cbz +; CHECK-BP: str +; CHECK-BP: str +; CHECK-BP: b +; CHECK-BP: str +; CHECK-BP: ldr +; CHECK-NOBP: ittee +; CHECK-NOBP: streq +; CHECK-NOBP: ldreq +; CHECK-NOBP: strne +; CHECK-NOBP: strne define i32 @diamond2(i32 %n, i32 %m, i32* %p, i32* %q) { entry: %tobool = icmp eq i32 %n, 0 @@ -111,6 +113,8 @@ entry: if.then: store i32 %n, i32* %p, align 4 + %arrayidx = getelementptr inbounds i32, i32* %p, i32 2 + store i32 %n, i32* %arrayidx, align 4 br label %if.end if.else: