[Mlir-commits] [mlir] 20768a9 - [ACC] Use ExistingOps strictness in ACCSpecializeForDevice for non-specialized functions (#187645)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Mar 20 08:56:01 PDT 2026


Author: khaki3
Date: 2026-03-20T08:55:57-07:00
New Revision: 20768a95765468ab64c6dd5674ce8f4e83c0a742

URL: https://github.com/llvm/llvm-project/commit/20768a95765468ab64c6dd5674ce8f4e83c0a742
DIFF: https://github.com/llvm/llvm-project/commit/20768a95765468ab64c6dd5674ce8f4e83c0a742.diff

LOG: [ACC] Use ExistingOps strictness in ACCSpecializeForDevice for non-specialized functions (#187645)

For non-specialized functions, ACCSpecializeForDevice collects ACC ops
inside compute constructs and applies device specialization patterns via
applyOpPatternsGreedily. With the default AnyOp strictness, the greedy
driver expands the worklist to parent ops when inner ops are modified,
accidentally unwrapping the parent acc.parallel via
ACCRegionUnwrapConversion. This leaves orphaned acc.loop
combined(parallel) ops that lose their parallelism and reduction
information downstream.

Set GreedyRewriteStrictness::ExistingOps so the greedy driver only
processes the initially collected inner ops, preserving the parent
compute construct for ACCComputeLowering to handle.

Added: 
    

Modified: 
    mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp
    mlir/test/Dialect/OpenACC/acc-specialize-for-device.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp b/mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp
index 79cc95a7b964d..e7bb9937fbf70 100644
--- a/mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp
+++ b/mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp
@@ -95,6 +95,11 @@ class ACCSpecializeForDevice
     } else {
       // For non-specialized functions, apply patterns only to ACC operations
       // inside compute constructs (not to the compute constructs themselves).
+      // Use ExistingOps strictness so the greedy driver does not expand the
+      // worklist to parent ops, which would accidentally unwrap the compute
+      // construct (e.g. after inlining acc routines with their own data
+      // regions).
+      config.setStrictness(GreedyRewriteStrictness::ExistingOps);
       SmallVector<Operation *> opsToTransform;
       func.walk([&](Operation *op) {
         if (isa<ACC_COMPUTE_CONSTRUCT_OPS>(op)) {

diff  --git a/mlir/test/Dialect/OpenACC/acc-specialize-for-device.mlir b/mlir/test/Dialect/OpenACC/acc-specialize-for-device.mlir
index 7f8267ddb779f..15e3e738010b7 100644
--- a/mlir/test/Dialect/OpenACC/acc-specialize-for-device.mlir
+++ b/mlir/test/Dialect/OpenACC/acc-specialize-for-device.mlir
@@ -79,6 +79,34 @@ func.func @copyin_outside_parallel(%arg0 : memref<i32>) {
   return
 }
 
+//===----------------------------------------------------------------------===//
+// Nested data constructs inside compute construct (non-specialized function).
+// After inlining an acc routine that has its own data region into a parallel
+// loop body, the inlined acc.data/acc.copyin end up inside acc.parallel.
+// The outer acc.parallel must NOT be unwrapped even though the inner data
+// ops are stripped. Regression test for greedy driver worklist expansion.
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: func.func @nested_data_inside_parallel
+// CHECK:       acc.copyin
+// CHECK:       acc.parallel
+// CHECK-NOT:   acc.data
+// CHECK-NOT:   acc.copyin
+// CHECK:       acc.yield
+func.func @nested_data_inside_parallel(%arg0 : memref<i32>, %arg1 : memref<i32>) {
+  %c0 = arith.constant 0 : i32
+  %0 = acc.copyin varPtr(%arg0 : memref<i32>) -> memref<i32>
+  acc.parallel dataOperands(%0 : memref<i32>) {
+    %1 = acc.copyin varPtr(%arg1 : memref<i32>) -> memref<i32>
+    acc.data dataOperands(%1 : memref<i32>) {
+      memref.store %c0, %arg1[] : memref<i32>
+      acc.terminator
+    }
+    acc.yield
+  }
+  return
+}
+
 //===----------------------------------------------------------------------===//
 // Data exit ops in specialized routines
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list