[llvm] r276910 - Codegen: IfConversion: Factor out a function to count dup instrs.
Kyle Butt via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 27 13:19:33 PDT 2016
Author: iteratee
Date: Wed Jul 27 15:19:33 2016
New Revision: 276910
URL: http://llvm.org/viewvc/llvm-project?rev=276910&view=rev
Log:
Codegen: IfConversion: Factor out a function to count dup instrs.
Factor out countDuplicatedInstructions to Count duplicated instructions at the
beginning and end of a diamond pattern. This is in prep for adding support for
diamonds that need to be tail-merged.
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=276910&r1=276909&r2=276910&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/IfConversion.cpp (original)
+++ llvm/trunk/lib/CodeGen/IfConversion.cpp Wed Jul 27 15:19:33 2016
@@ -540,39 +540,15 @@ bool IfConverter::ValidTriangle(BBInfo &
return TExit && TExit == FalseBBI.BB;
}
-/// ValidDiamond - Returns true if the 'true' and 'false' blocks (along
-/// with their common predecessor) forms a valid diamond shape for ifcvt.
-bool IfConverter::ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
- unsigned &Dups1, unsigned &Dups2) const {
- Dups1 = Dups2 = 0;
- if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
- FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
- return false;
-
- MachineBasicBlock *TT = TrueBBI.TrueBB;
- MachineBasicBlock *FT = FalseBBI.TrueBB;
+static void countDuplicatedInstructions(
+ MachineBasicBlock::iterator &TIB,
+ MachineBasicBlock::iterator &FIB,
+ MachineBasicBlock::iterator &TIE,
+ MachineBasicBlock::iterator &FIE,
+ unsigned &Dups1, unsigned &Dups2,
+ MachineBasicBlock &TBB, MachineBasicBlock &FBB,
+ bool SkipConditionalBranches) {
- if (!TT && blockAlwaysFallThrough(TrueBBI))
- TT = getNextBlock(TrueBBI.BB);
- if (!FT && blockAlwaysFallThrough(FalseBBI))
- FT = getNextBlock(FalseBBI.BB);
- if (TT != FT)
- return false;
- if (!TT && (TrueBBI.IsBrAnalyzable || FalseBBI.IsBrAnalyzable))
- return false;
- if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
- return false;
-
- // FIXME: Allow true block to have an early exit?
- if (TrueBBI.FalseBB || FalseBBI.FalseBB ||
- (TrueBBI.ClobbersPred && FalseBBI.ClobbersPred))
- return false;
-
- // Count duplicate instructions at the beginning of the true and false blocks.
- MachineBasicBlock::iterator TIB = TrueBBI.BB->begin();
- MachineBasicBlock::iterator FIB = FalseBBI.BB->begin();
- MachineBasicBlock::iterator TIE = TrueBBI.BB->end();
- MachineBasicBlock::iterator FIE = FalseBBI.BB->end();
while (TIB != TIE && FIB != FIE) {
// Skip dbg_value instructions. These do not count.
if (TIB->isDebugValue()) {
@@ -601,20 +577,27 @@ bool IfConverter::ValidDiamond(BBInfo &T
// can be left unpredicated.
// Check for already containing all of the block.
if (TIB == TIE || FIB == FIE)
- return true;
+ return;
--TIE;
--FIE;
- if (!TrueBBI.BB->succ_empty() || !FalseBBI.BB->succ_empty()) {
- while (TIE != TIB && TIE->isBranch())
- --TIE;
- while (FIE != FIB && FIE->isBranch())
- --FIE;
+ if (!TBB.succ_empty() || !FBB.succ_empty()) {
+ if (SkipConditionalBranches) {
+ while (TIE != TIB && TIE->isBranch())
+ --TIE;
+ while (FIE != FIB && FIE->isBranch())
+ --FIE;
+ } else {
+ while (TIE != TIB && TIE->isUnconditionalBranch())
+ --TIE;
+ while (FIE != FIB && FIE->isUnconditionalBranch())
+ --FIE;
+ }
}
// If Dups1 includes all of a block, then don't count duplicate
// instructions at the end of the blocks.
if (TIB == TIE || FIB == FIE)
- return true;
+ return;
// Count duplicate instructions at the ends of the blocks.
while (TIE != TIB && FIE != FIB) {
@@ -633,11 +616,52 @@ bool IfConverter::ValidDiamond(BBInfo &T
}
if (!TIE->isIdenticalTo(*FIE))
break;
- ++Dups2;
+ // If we are trying to make sure the conditional branches are the same, we
+ // still don't want to count them.
+ if (SkipConditionalBranches || !TIE->isBranch())
+ ++Dups2;
--TIE;
--FIE;
}
+}
+
+/// ValidDiamond - Returns true if the 'true' and 'false' blocks (along
+/// with their common predecessor) forms a valid diamond shape for ifcvt.
+bool IfConverter::ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
+ unsigned &Dups1, unsigned &Dups2) const {
+ Dups1 = Dups2 = 0;
+ if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
+ FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
+ return false;
+
+ MachineBasicBlock *TT = TrueBBI.TrueBB;
+ MachineBasicBlock *FT = FalseBBI.TrueBB;
+
+ if (!TT && blockAlwaysFallThrough(TrueBBI))
+ TT = getNextBlock(TrueBBI.BB);
+ if (!FT && blockAlwaysFallThrough(FalseBBI))
+ FT = getNextBlock(FalseBBI.BB);
+ if (TT != FT)
+ return false;
+ if (!TT && (TrueBBI.IsBrAnalyzable || FalseBBI.IsBrAnalyzable))
+ return false;
+ if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
+ return false;
+ // FIXME: Allow true block to have an early exit?
+ if (TrueBBI.FalseBB || FalseBBI.FalseBB ||
+ (TrueBBI.ClobbersPred && FalseBBI.ClobbersPred))
+ return false;
+
+ // Count duplicate instructions at the beginning and end of the true and
+ // false blocks.
+ MachineBasicBlock::iterator TIB = TrueBBI.BB->begin();
+ MachineBasicBlock::iterator FIB = FalseBBI.BB->begin();
+ MachineBasicBlock::iterator TIE = TrueBBI.BB->end();
+ MachineBasicBlock::iterator FIE = FalseBBI.BB->end();
+ countDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
+ *TrueBBI.BB, *FalseBBI.BB,
+ /* SkipConditionalBranches */ true);
return true;
}
More information about the llvm-commits
mailing list