Skip to content

Commit 82701d8

Browse files
committed
[SYCL][Native CPU] Avoid dangling references.
In multiple places, we take a reference to an element in LoopMasks and expect that reference to remain valid. LoopMasks is a DenseMap which does not promise that references to existing elements remain valid as new elements are inserted. We pre-populate LoopMasks to try and avoid this becoming a problem, but we were pre-populating it only with top-level loops, when sub-loops may also cause references to become invalid. Adjust the pre-population to take all loops into account.
1 parent 596d557 commit 82701d8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/lib/SYCLNativeCPUUtils/compiler_passes/vecz/source/transform/control_flow_conversion_pass.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class ControlFlowConversionState::Impl : public ControlFlowConversionState {
115115
Instruction *persistedCombinedDivergentExitMask = nullptr;
116116
};
117117

118+
/// @brief Create loop masks for the specified loop and its subloops.
119+
/// @param[in] L Loop which should have its LoopMasksInfo created.
120+
void createLoopMasks(Loop *L);
121+
118122
/// @brief Convert the function's CFG to data-flow.
119123
/// @return true if the function's CFG was converted, false otherwise.
120124
bool convertToDataFlow();
@@ -538,6 +542,13 @@ bool ControlFlowConversionState::replaceReachableUses(Reachability &RC,
538542
return true;
539543
}
540544

545+
void ControlFlowConversionState::Impl::createLoopMasks(Loop *L) {
546+
LoopMasks[L];
547+
for (auto *L : L->getSubLoops()) {
548+
createLoopMasks(L);
549+
}
550+
}
551+
541552
bool ControlFlowConversionState::Impl::convertToDataFlow() {
542553
DT = &AM.getResult<DominatorTreeAnalysis>(F);
543554
PDT = &AM.getResult<PostDominatorTreeAnalysis>(F);
@@ -546,7 +557,7 @@ bool ControlFlowConversionState::Impl::convertToDataFlow() {
546557

547558
// Make sure every loop has an entry in the masks table before we start.
548559
for (auto *L : *LI) {
549-
LoopMasks[L];
560+
createLoopMasks(L);
550561
}
551562

552563
if (!VU.choices().linearizeBOSCC()) {

0 commit comments

Comments
 (0)