Fix bug in block reorder heuristic

Summary:
Tests with SPEC CPU2006 400.perlbench exposed a bug in the block reordering
heuristic that happened when two blocks are both successor and predecessor of
each other. This patch fixes this.

(cherry picked from FBD2555835)
This commit is contained in:
Rafael Auler
2015-10-19 10:43:54 -07:00
committed by Maksim Panchenko
parent 31e6bd1226
commit ef059af3d1

View File

@@ -582,17 +582,20 @@ void BinaryFunction::optimizeLayout(bool DumpLayout) {
// Case 2: Both BBSrc and BBDst are already allocated
if ((I = BBToClusterMap[BBSrc]) != -1 &&
(J = BBToClusterMap[BBDst]) != -1) {
// Case 2a: If they are already allocated at the same cluster, ignore
if (I == J)
continue;
auto &ClusterA = Clusters[I];
auto &ClusterB = Clusters[J];
if (ClusterA.back() == BBSrc && ClusterB.front() == BBDst) {
// Case 2a: BBSrc is at the end of a cluster and BBDst is at the start,
// Case 2b: BBSrc is at the end of a cluster and BBDst is at the start,
// allowing us to merge two clusters
for (auto BB : ClusterB)
BBToClusterMap[BB] = I;
ClusterA.insert(ClusterA.end(), ClusterB.begin(), ClusterB.end());
ClusterB.clear();
} else {
// Case 2b: Both BBSrc and BBDst are allocated in positions we cannot
// Case 2c: Both BBSrc and BBDst are allocated in positions we cannot
// merge them, so we ignore this edge.
}
continue;
@@ -649,8 +652,9 @@ void BinaryFunction::optimizeLayout(bool DumpLayout) {
// Finalize layout with BBs that weren't assigned to any cluster, preserving
// their relative order
for (auto &BB : BasicBlocks) {
if (BBToClusterMap[&BB] == -1)
if (BBToClusterMap[&BB] == -1) {
BasicBlocksLayout.push_back(&BB);
}
}
if (DumpLayout) {