Skip to content

Commit b69f6eb

Browse files
committed
[Uniformity] Fixed control-div early stop
Control-divergence finds joins by propagating labels from the divergent control branch. The code checking if the early stop is reached is not correct. This change fixes this issue by checking if a join is reached. The propagation is still the same in which propagation starts by adding successors of the divergent block into a set first and then propagate one from the set in the toplogical order. If there is only one block in the set, then this block must be a join block, and thus propagation stops.
1 parent 54aa16d commit b69f6eb

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

llvm/include/llvm/ADT/GenericUniformityImpl.h

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,6 @@ template <typename ContextT> class DivergencePropagator {
610610
LLVM_DEBUG(dbgs() << "SDA:computeJoinPoints: "
611611
<< Context.print(&DivTermBlock) << "\n");
612612

613-
// Early stopping criterion
614-
int FloorIdx = CyclePOT.size() - 1;
615-
const BlockT *FloorLabel = nullptr;
616613
int DivTermIdx = CyclePOT.getIndex(&DivTermBlock);
617614

618615
// Bootstrap with branch targets
@@ -626,15 +623,19 @@ template <typename ContextT> class DivergencePropagator {
626623
LLVM_DEBUG(dbgs() << "\tImmediate divergent cycle exit: "
627624
<< Context.print(SuccBlock) << "\n");
628625
}
629-
auto SuccIdx = CyclePOT.getIndex(SuccBlock);
630626
visitEdge(*SuccBlock, *SuccBlock);
631-
FloorIdx = std::min<int>(FloorIdx, SuccIdx);
632627
}
633628

634-
while (true) {
629+
630+
// Propagation shall stop at the IPD (immediate post-dominator)
631+
// of DivTemBlock.
632+
//
633+
// If the number of blocks in FreshLabels is one, the block in FreshLabels
634+
// must be a PD. As propagation follows RPO, the first PD reached should
635+
// be IPD.
636+
while (FreshLabels.count() > 1) {
635637
auto BlockIdx = FreshLabels.find_last();
636-
if (BlockIdx == -1 || BlockIdx < FloorIdx)
637-
break;
638+
assert(BlockIdx >= 0);
638639

639640
LLVM_DEBUG(dbgs() << "Current labels:\n"; printDefs(dbgs()));
640641

@@ -651,9 +652,6 @@ template <typename ContextT> class DivergencePropagator {
651652
const auto *Label = BlockLabels[Block];
652653
assert(Label);
653654

654-
bool CausedJoin = false;
655-
int LoweredFloorIdx = FloorIdx;
656-
657655
// If the current block is the header of a reducible cycle that
658656
// contains the divergent branch, then the label should be
659657
// propagated to the cycle exits. Such a header is the "last
@@ -681,28 +679,11 @@ template <typename ContextT> class DivergencePropagator {
681679
if (const auto *BlockCycle = getReducibleParent(Block)) {
682680
SmallVector<BlockT *, 4> BlockCycleExits;
683681
BlockCycle->getExitBlocks(BlockCycleExits);
684-
for (auto *BlockCycleExit : BlockCycleExits) {
685-
CausedJoin |= visitCycleExitEdge(*BlockCycleExit, *Label);
686-
LoweredFloorIdx =
687-
std::min<int>(LoweredFloorIdx, CyclePOT.getIndex(BlockCycleExit));
688-
}
682+
for (auto *BlockCycleExit : BlockCycleExits)
683+
visitCycleExitEdge(*BlockCycleExit, *Label);
689684
} else {
690-
for (const auto *SuccBlock : successors(Block)) {
691-
CausedJoin |= visitEdge(*SuccBlock, *Label);
692-
LoweredFloorIdx =
693-
std::min<int>(LoweredFloorIdx, CyclePOT.getIndex(SuccBlock));
694-
}
695-
}
696-
697-
// Floor update
698-
if (CausedJoin) {
699-
// 1. Different labels pushed to successors
700-
FloorIdx = LoweredFloorIdx;
701-
} else if (FloorLabel != Label) {
702-
// 2. No join caused BUT we pushed a label that is different than the
703-
// last pushed label
704-
FloorIdx = LoweredFloorIdx;
705-
FloorLabel = Label;
685+
for (const auto *SuccBlock : successors(Block))
686+
visitEdge(*SuccBlock, *Label);
706687
}
707688
}
708689

0 commit comments

Comments
 (0)