Skip to content

[Uniformity] Fixed control-div early stop #138806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions llvm/include/llvm/ADT/GenericUniformityImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,55 @@ template <typename ContextT> class DivergencePropagator {
return true;
}

// getRealSucc() gets all successors of \p SuccBlock that can be merged with it
// and returns the last one of them (called it real succ of SuccBlock).
// For example,
//
// div-b0
// / \
// b1 b2
// | |
// b3 b4
// | /
// b5 /
// \ /
// \ /
// b6
//
// For \p SuccBlock = b1, {b1, b3, b5} can be merged together and this
// function returns the last one b5; for \p SuccBlock = b2, {b2, b4} can
// be merged and this function returns b4.
//
// This is necessary as the algorithm of propagating control-divergence
// assumes that CFG has been optimized so that (b1,b3,b5) and (b2, b4)
// are merged into a single block, respectively.
const BlockT* getRealSucc(const BlockT& SuccBlock, const BlockT& Label) {
const BlockT *LastBlock = &SuccBlock;
if (pred_size(LastBlock) != 1)
return LastBlock;

while (succ_size(LastBlock) == 1) {
const BlockT* NextBlock = *succ_begin(LastBlock);

if (pred_size(NextBlock) != 1)
break;

// NextBlock can be merged into LastBlock
const auto *OldLabel = BlockLabels[LastBlock];
assert(OldLabel == nullptr);

LLVM_DEBUG(dbgs() << "labeling (for non real succ) "
<< Context.print(LastBlock) << ":\n"
<< "\tpushed label: " << Context.print(&Label) << "\n"
<< "\told label: " << Context.print(OldLabel) << "\n");

BlockLabels[LastBlock] = &Label;
LastBlock = NextBlock;
}

return LastBlock;
}

std::unique_ptr<DivergenceDescriptorT> computeJoinPoints() {
assert(DivDesc);

Expand All @@ -626,8 +675,9 @@ template <typename ContextT> class DivergencePropagator {
LLVM_DEBUG(dbgs() << "\tImmediate divergent cycle exit: "
<< Context.print(SuccBlock) << "\n");
}
auto SuccIdx = CyclePOT.getIndex(SuccBlock);
visitEdge(*SuccBlock, *SuccBlock);
const auto* SuccBB = getRealSucc(*SuccBlock, *SuccBlock);
auto SuccIdx = CyclePOT.getIndex(SuccBB);
visitEdge(*SuccBB, *SuccBlock);
FloorIdx = std::min<int>(FloorIdx, SuccIdx);
}

Expand Down Expand Up @@ -688,9 +738,10 @@ template <typename ContextT> class DivergencePropagator {
}
} else {
for (const auto *SuccBlock : successors(Block)) {
CausedJoin |= visitEdge(*SuccBlock, *Label);
const auto* SuccBB = getRealSucc(*SuccBlock, *Label);
CausedJoin |= visitEdge(*SuccBB, *Label);
LoweredFloorIdx =
std::min<int>(LoweredFloorIdx, CyclePOT.getIndex(SuccBlock));
std::min<int>(LoweredFloorIdx, CyclePOT.getIndex(SuccBB));
}
}

Expand Down
Loading