diff --git a/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td b/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td index e38738230ffbc..07bb47e26b968 100644 --- a/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td +++ b/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td @@ -26,8 +26,7 @@ include "mlir/IR/BuiltinAttributes.td" class cuf_Op traits> : Op; -def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments, - MemoryEffects<[MemAlloc]>]> { +def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments]> { let summary = "Allocate an object on device"; let description = [{ @@ -47,7 +46,9 @@ def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments, cuf_DataAttributeAttr:$data_attr ); - let results = (outs fir_ReferenceType:$ptr); + // Value-scoped Allocate on the returned reference + let results = + (outs Res]>:$ptr); let assemblyFormat = [{ $in_type (`(` $typeparams^ `:` type($typeparams) `)`)? diff --git a/flang/test/Analysis/AliasAnalysis/cuf-alloc-source-kind.mlir b/flang/test/Analysis/AliasAnalysis/cuf-alloc-source-kind.mlir new file mode 100644 index 0000000000000..f062dcb3a3360 --- /dev/null +++ b/flang/test/Analysis/AliasAnalysis/cuf-alloc-source-kind.mlir @@ -0,0 +1,22 @@ +// REQUIRES: asserts +// RUN: fir-opt %s -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis))' -debug-only=fir-alias-analysis --mlir-disable-threading 2>&1 | FileCheck %s + +// Verify that a CUF allocation is recognized as SourceKind::Allocate by +// fir::AliasAnalysis::getSource. + +module { + func.func @_QQmain() attributes {fir.bindc_name = "TEST"} { + // Allocate two independent device arrays and tag the results; with + // value-scoped MemAlloc handling in AA, these should be classified as + // Allocate and not alias. + %a = cuf.alloc !fir.box>> {bindc_name = "a1", data_attr = #cuf.cuda, uniq_name = "_QFEa1", test.ptr = "cuf_alloc_a"} -> !fir.ref>>> + %b = cuf.alloc !fir.box>> {bindc_name = "a2", data_attr = #cuf.cuda, uniq_name = "_QFEa2", test.ptr = "cuf_alloc_b"} -> !fir.ref>>> + return + } +} + +// CHECK-LABEL: Testing : "_QQmain" +// Distinct allocations should not alias. +// CHECK: cuf_alloc_a#0 <-> cuf_alloc_b#0: NoAlias + +