[Mlir-commits] [flang] [mlir] [Flang][OpenMP] Don't generate code for unreachable target regions. (PR #178937)
Pranav Bhandarkar
llvmlistbot at llvm.org
Fri Jan 30 21:11:05 PST 2026
https://github.com/bhandarkar-pranav commented:
Thank you for the PR, @abidh. This is a good first pass, but I have some thoughts
1. Any reason, you haven't styled this as a forward pass from the entry block to compute reachabililty and then check the omp.target for membership of the set of reachable block/ops? The reason, I say this is that in `IsUnreachableBlock` we do not identify transitively dead (although perhaps rare) omp.target ops. Consider a CFG like
```
bb0
cf.cond_br false, bb1, bb2
bb1
cf.br bb3
bb2
cf.br bb4
bb3:
omp.target // Since `IsUnreachableBlock` only checks predecessors of the block of
// omp.target, and bb1 doesn't terminate with cf.cond_br this function
// would miss this case.
bb4:
return
```
2. MLIR has `DominanceInfo::isReachableFromEntry()`. When combined with `SCCPPass` you could get what you want for free
```
pm.addPass(createSCCPPass()); // Fold constant branches
pm.addPass(createCanonicalizerPass()); // Clean up
pm.addPass(flangomp::createMarkUnreachableTargetsPass()); // now use DominanceInfo::isReachableFromEntry
```
https://github.com/llvm/llvm-project/pull/178937
More information about the Mlir-commits
mailing list