[llvm] r307788 - [ARM] Adjust ifcvt heuristic for the diamond ifcvt case

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 06:23:10 PDT 2017


Author: john.brawn
Date: Wed Jul 12 06:23:10 2017
New Revision: 307788

URL: http://llvm.org/viewvc/llvm-project?rev=307788&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
    llvm/trunk/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=307788&r1=307787&r2=307788&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp Wed Jul 12 06:23:10 2017
@@ -1880,6 +1880,9 @@ isProfitableToIfCvt(MachineBasicBlock &T
       // 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);

Modified: llvm/trunk/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll?rev=307788&r1=307787&r2=307788&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb2/ifcvt-no-branch-predictor.ll Wed Jul 12 06:23:10 2017
@@ -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:




More information about the llvm-commits mailing list