Skip to content

Commit 89b45d3

Browse files
authored
[mlir][OpenMP] Fix reduction selection when debug data is present. (llvm#1035)
openmp only does not break hipCatc2 [2025-03-07T15:44:30.064Z] 1360 - Unit_hipMalloc3DArray_MaxTexture - uint4 (Subprocess killed) [2025-03-07T15:44:30.064Z] 1389 - Unit_hipArray3DCreate_MaxTexture - uint4 (Subprocess killed)
2 parents f29ab0d + 7ac25ae commit 89b45d3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,10 +1718,18 @@ static bool teamsReductionContainedInDistribute(omp::TeamsOp teamsOp) {
17181718
llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(teamsOp.getOperation());
17191719
// Check that all uses of the reduction block arg has the same distribute op
17201720
// parent.
1721+
llvm::SmallVector<mlir::Operation *> debugUses;
17211722
Operation *distOp = nullptr;
17221723
for (auto ra : iface.getReductionBlockArgs())
17231724
for (auto &use : ra.getUses()) {
17241725
auto *useOp = use.getOwner();
1726+
// Ignore debug uses.
1727+
if (mlir::isa<LLVM::DbgDeclareOp>(useOp) ||
1728+
mlir::isa<LLVM::DbgValueOp>(useOp)) {
1729+
debugUses.push_back(useOp);
1730+
continue;
1731+
}
1732+
17251733
auto currentDistOp = useOp->getParentOfType<omp::DistributeOp>();
17261734
// Use is not inside a distribute op - return false
17271735
if (!currentDistOp)
@@ -1733,6 +1741,12 @@ static bool teamsReductionContainedInDistribute(omp::TeamsOp teamsOp) {
17331741

17341742
distOp = currentOp;
17351743
}
1744+
1745+
// If we are going to use distribute reduction then remove any debug uses of
1746+
// the reduction parameters in teamsOp. Otherwise they will be left without
1747+
// any mapped value in moduleTranslation and will eventually error out.
1748+
for (auto use : debugUses)
1749+
use->erase();
17361750
return true;
17371751
}
17381752

0 commit comments

Comments
 (0)