summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/EarlyIfConversion.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2012-08-07 18:02:19 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2012-08-07 18:02:19 +0000
commit75d9d5159e70b9255a65aed45fd1adefde0be7c8 (patch)
treee0fc1ae5da4be3b9c2759592c9601106df87e347 /llvm/lib/CodeGen/EarlyIfConversion.cpp
parentd39041f2fc7c5734da8b5dede5caac23713e9236 (diff)
downloadbcm5719-llvm-75d9d5159e70b9255a65aed45fd1adefde0be7c8.tar.gz
bcm5719-llvm-75d9d5159e70b9255a65aed45fd1adefde0be7c8.zip
Add trace accessor methods, implement primitive if-conversion heuristic.
Compare the critical paths of the two traces through an if-conversion candidate. If the difference is larger than the branch brediction penalty, reject the if-conversion. If would never pay. llvm-svn: 161433
Diffstat (limited to 'llvm/lib/CodeGen/EarlyIfConversion.cpp')
-rw-r--r--llvm/lib/CodeGen/EarlyIfConversion.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index e49b9d3e18e..8adaa6dd0bf 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -601,10 +601,24 @@ void EarlyIfConverter::invalidateTraces() {
bool EarlyIfConverter::shouldConvertIf() {
if (!MinInstr)
MinInstr = Traces->getEnsemble(MachineTraceMetrics::TS_MinInstrCount);
- DEBUG({
- dbgs() << MinInstr->getTrace(IfConv.Head);
- MinInstr->print(dbgs());
- });
+
+ // MCSchedModel doesn't yet provide a misprediction penalty.
+ unsigned MispredictPenalty = 10;
+
+ // Compare the critical path through TBB and FBB. If the difference is
+ // greater than the branch misprediction penalty, it would never pay to
+ // if-convert. The triangle/diamond topology guarantees that these traces
+ // have the same head and tail, so they can be compared.
+ MachineTraceMetrics::Trace TBBTrace = MinInstr->getTrace(IfConv.TBB);
+ MachineTraceMetrics::Trace FBBTrace = MinInstr->getTrace(IfConv.FBB);
+ DEBUG(dbgs() << "TBB: " << TBBTrace << "FBB: " << FBBTrace);
+ unsigned TBBCrit = TBBTrace.getCriticalPath();
+ unsigned FBBCrit = FBBTrace.getCriticalPath();
+ unsigned ExtraCrit = TBBCrit > FBBCrit ? TBBCrit-FBBCrit : FBBCrit-TBBCrit;
+ if (ExtraCrit >= MispredictPenalty) {
+ DEBUG(dbgs() << "Critical path difference too large.\n");
+ return false;
+ }
return true;
}
OpenPOWER on IntegriCloud