[Mlir-commits] [mlir] [mlir][gpu] Loose the condition to convert scf.parallel to gpu.launch (PR #164978)
Hsiangkai Wang
llvmlistbot at llvm.org
Wed Oct 29 07:14:34 PDT 2025
================
@@ -625,18 +627,49 @@ ParallelToGpuLaunchLowering::matchAndRewrite(ParallelOp parallelOp,
bool seenSideeffects = false;
// Whether we have left a nesting scope (and hence are no longer innermost).
bool leftNestingScope = false;
+ LocalAliasAnalysis aliasAnalysis;
+ llvm::DenseSet<Value> writtenBuffer;
while (!worklist.empty()) {
Operation *op = worklist.pop_back_val();
// Now walk over the body and clone it.
// TODO: This is only correct if there either is no further scf.parallel
- // nested or this code is side-effect free. Otherwise we might need
- // predication. We are overly conservative for now and only allow
- // side-effects in the innermost scope.
+ // nested or this code has side-effect but the memory buffer is not
+ // alias to inner loop access buffer. Otherwise we might need
+ // predication.
if (auto nestedParallel = dyn_cast<ParallelOp>(op)) {
// Before entering a nested scope, make sure there have been no
- // sideeffects until now.
- if (seenSideeffects)
- return failure();
+ // sideeffects until now or the nested operations do not access the
+ // buffer written by outer scope.
+ if (seenSideeffects) {
+ bool accessesWrittenBuffer = false;
+ nestedParallel.walk([&](Operation *nestedOp) {
+ if (accessesWrittenBuffer)
+ return;
+ if (isMemoryEffectFree(nestedOp))
+ return;
+
+ if (auto memEffectInterface =
+ dyn_cast<MemoryEffectOpInterface>(nestedOp)) {
+ SmallVector<MemoryEffects::EffectInstance> effects;
+ memEffectInterface.getEffects(effects);
+ for (const auto &effect : effects) {
+ if (isa<MemoryEffects::Read>(effect.getEffect()) ||
----------------
Hsiangkai wrote:
Done.
https://github.com/llvm/llvm-project/pull/164978
More information about the Mlir-commits
mailing list