diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h --- a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h +++ b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h @@ -22,6 +22,10 @@ bool isFortranVariableType(mlir::Type); bool isFortranScalarCharacterType(mlir::Type); bool isFortranScalarCharacterExprType(mlir::Type); +bool isFortranScalarNumericalType(mlir::Type); +bool isFortranNumericalBoxRefArrayOrExprType(mlir::Type); +bool isI1Type(mlir::Type); +bool isFortranLogicalOrI1BoxRefArrayOrExprType(mlir::Type); } // namespace hlfir #include "flang/Optimizer/HLFIR/HLFIRDialect.h.inc" diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td --- a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td @@ -75,6 +75,15 @@ return hlfir::ExprType::get(eleTy.getContext(), Shape{}, eleTy, isPolymorphic()); } + + // Is the shape of the sequence dynamic? + bool hasDynamicExtents() const { + for (const auto d : getShape()) + if (d == getUnknownExtent()) + return true; + return false; + } + static constexpr int64_t getUnknownExtent() { return mlir::ShapedType::kDynamic; } @@ -108,4 +117,14 @@ def AnyScalarCharacterExpr : Type; +def IsFortranNumericalBoxRefArrayOrExprTypePred + : CPred<"::hlfir::isFortranNumericalBoxRefArrayOrExprType($_self)">; +def AnyFortranNumericalBoxRefArrayOrExpr : Type; + +def IsFortranLogicalOrI1BoxRefArrayOrExprTypePred + : CPred<"::hlfir::isFortranLogicalOrI1BoxRefArrayOrExprType($_self)">; +def AnyFortranLogicalOrI1BoxRefArrayOrExpr : Type; + #endif // FORTRAN_DIALECT_HLFIR_OP_BASE diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td --- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td @@ -256,6 +256,32 @@ let builders = [OpBuilder<(ins "mlir::Value":$string,"mlir::Value":$len)>]; } +def hlfir_SumOp : hlfir_Op<"sum", []> { + let summary = "SUM transformational intrinsic"; + let description = [{ + Sums the elements of an array, optionally along a particular dimension, + optionally if a mask is true. + }]; + + let arguments = (ins + AnyFortranNumericalBoxRefArrayOrExpr:$array, + Variadic:$optionals + ); + + let results = (outs hlfir_ExprType); + + let assemblyFormat = [{ + $array $optionals attr-dict `:` functional-type(operands, results) + }]; + + let extraClassDeclaration = [{ + mlir::Value getDim(); + mlir::Value getMask(); + }]; + + let hasVerifier = 1; +} + def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments, DeclareOpInterfaceMethods]> { let summary = "Create a variable from an expression value"; diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp --- a/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIRDialect.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/HLFIR/HLFIRDialect.h" +#include "flang/Optimizer/Dialect/FIRType.h" #include "flang/Optimizer/HLFIR/HLFIROps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" @@ -99,3 +100,39 @@ exprType.getElementType().isa(); return false; } + +bool hlfir::isFortranScalarNumericalType(mlir::Type type) { + return fir::isa_integer(type) || fir::isa_real(type) || + fir::isa_complex(type); +} + +static mlir::Type unwrapBoxArrayOrExpr(mlir::Type type) { + while (type.isa()) + type = mlir::TypeSwitch(type) + .Case([](auto t) { return t.getEleTy(); }); + return type; +} + +bool hlfir::isFortranNumericalBoxRefArrayOrExprType(mlir::Type type) { + mlir::Type unwrappedType = unwrapBoxArrayOrExpr(type); + if (unwrappedType) + return isFortranScalarNumericalType(unwrappedType); + return false; +} + +bool hlfir::isI1Type(mlir::Type type) { + if (mlir::IntegerType integer = type.dyn_cast()) + if (integer.getWidth() == 1) + return true; + return false; +} + +bool hlfir::isFortranLogicalOrI1BoxRefArrayOrExprType(mlir::Type type) { + mlir::Type unwrappedType = unwrapBoxArrayOrExpr(type); + if (unwrappedType) + return mlir::isa(unwrappedType) || + isI1Type(unwrappedType); + return false; +} diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -12,6 +12,8 @@ #include "flang/Optimizer/HLFIR/HLFIROps.h" #include "flang/Optimizer/Dialect/FIROpsSupport.h" +#include "flang/Optimizer/Dialect/FIRType.h" +#include "flang/Optimizer/HLFIR/HLFIRDialect.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/DialectImplementation.h" @@ -420,6 +422,136 @@ build(builder, result, resultType, string, len); } +//===----------------------------------------------------------------------===// +// SumOp +//===----------------------------------------------------------------------===// + +mlir::Value hlfir::SumOp::getDim() { + mlir::Value dim; + + for (mlir::Value arg : getOptionals()) { + mlir::Type ty = arg.getType(); + + if (hlfir::isFortranLogicalOrI1BoxRefArrayOrExprType(ty)) + // mask argument + continue; + + if (fir::isa_integer(ty) || ty.isa()) { + dim = arg; + break; + } + } + + return dim; +} + +mlir::Value hlfir::SumOp::getMask() { + mlir::Value mask; + + for (mlir::Value arg : getOptionals()) { + mlir::Type ty = arg.getType(); + if (hlfir::isFortranLogicalOrI1BoxRefArrayOrExprType(ty)) { + mask = arg; + break; + } + } + + return mask; +} + +static mlir::Type unwrapType(mlir::Type type) { + return mlir::TypeSwitch(type) + .Case( + [](auto container) { return container.getEleTy(); }) + .Default([](mlir::Type type) { return type; }); +} + +static std::optional>> +getArrayOrExprTypeShape(mlir::Type arrayOrExpr) { + if (auto array = arrayOrExpr.dyn_cast()) + return {{array.getEleTy(), array.getShape()}}; + if (auto expr = arrayOrExpr.dyn_cast()) { + if (!expr.isArray()) + return {}; + return {{expr.getEleTy(), expr.getShape()}}; + } + return {}; +} + +mlir::LogicalResult hlfir::SumOp::verify() { + mlir::Operation *op = getOperation(); + + auto results = op->getResultTypes(); + assert(results.size() == 1); + + auto args = op->getOperands(); + assert(args.size() > 0); // array argument is compulsory + if (args.size() > 3) + return emitOpError("too many arguments"); + + mlir::Value array = args[0]; + mlir::Value mask = getMask(); + + mlir::Type arrayTy = unwrapType(array.getType()); + hlfir::ExprType resultTy = results[0].cast(); + auto arrayInfo = getArrayOrExprTypeShape(arrayTy); + if (!arrayInfo) + return emitOpError("ARRAY argument must be an array"); + auto [numTy, arrayShape] = *arrayInfo; + + // checked in tblgen: + assert(hlfir::isFortranScalarNumericalType(numTy)); + + if (mask) { + mlir::Type maskTy = unwrapType(mask.getType()); + mlir::Type maskScalarTy; + llvm::ArrayRef maskShape; + + auto maskInfo = getArrayOrExprTypeShape(maskTy); + if (!maskInfo) + maskScalarTy = maskTy; + else { + maskScalarTy = std::get<0>(*maskInfo); + maskShape = std::get<1>(*maskInfo); + } + + if (!maskShape.empty()) { + if (maskShape.size() != arrayShape.size()) + return emitOpError("MASK must be conformable to ARRAY"); + static_assert(fir::SequenceType::getUnknownExtent() == + hlfir::ExprType::getUnknownExtent()); + constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent(); + for (std::size_t i = 0; i < arrayShape.size(); ++i) { + int64_t arrayExtent = arrayShape[i]; + int64_t maskExtent = maskShape[i]; + if ((arrayExtent != maskExtent) && (arrayExtent != unknownExtent) && + (maskExtent != unknownExtent)) + return emitOpError("MASK must be conformable to ARRAY"); + } + } + } + + if (resultTy.isArray()) { + // Result is of the same type as ARRAY + if (resultTy.getEleTy() != numTy) + return emitOpError( + "result must have the same element type as ARRAY argument"); + + llvm::ArrayRef resultShape = resultTy.getShape(); + + // Result has rank n-1 + if (resultShape.size() != (arrayShape.size() - 1)) + return emitOpError("result rank must be one less than ARRAY"); + } else { + // Result is of the same type as ARRAY + if (resultTy.getElementType() != numTy) + return emitOpError( + "result must have the same element type as ARRAY argument"); + } + + return mlir::success(); +} + //===----------------------------------------------------------------------===// // AssociateOp //===----------------------------------------------------------------------===// diff --git a/flang/test/HLFIR/invalid.fir b/flang/test/HLFIR/invalid.fir --- a/flang/test/HLFIR/invalid.fir +++ b/flang/test/HLFIR/invalid.fir @@ -295,3 +295,33 @@ %0 = hlfir.concat %arg0 len %c30 : (!fir.ref>, index) -> (!hlfir.expr>) return } + +// ----- +func.func @bad_sum0(%arg0: !hlfir.expr, %arg1: i32, %arg2: !fir.box>) { + // expected-error@+1 {{'hlfir.sum' op ARRAY argument must be an array}} + %0 = hlfir.sum %arg0 %arg1, %arg2 : (!hlfir.expr, i32, !fir.box>) -> !hlfir.expr +} + +// ----- +func.func @bad_sum1(%arg0: !hlfir.expr, %arg1: i32, %arg2: !fir.box>) { + // expected-error@+1 {{'hlfir.sum' op result must have the same element type as ARRAY argument}} + %0 = hlfir.sum %arg0 %arg1, %arg2 : (!hlfir.expr, i32, !fir.box>) -> !hlfir.expr +} + +// ----- +func.func @bad_sum2(%arg0: !hlfir.expr, %arg1: i32, %arg2: !fir.box>>) { + // expected-error@+1 {{'hlfir.sum' op MASK must be conformable to ARRAY}} + %0 = hlfir.sum %arg0 %arg1, %arg2 : (!hlfir.expr, i32, !fir.box>>) -> !hlfir.expr +} + +// ----- +func.func @bad_sum3(%arg0: !hlfir.expr, %arg1: i32, %arg2: !fir.box>>) { + // expected-error@+1 {{'hlfir.sum' op MASK must be conformable to ARRAY}} + %0 = hlfir.sum %arg0 %arg1, %arg2 : (!hlfir.expr, i32, !fir.box>>) -> !hlfir.expr +} + +// ----- +func.func @bad_sum4(%arg0: !hlfir.expr, %arg1: i32, %arg2: !fir.box>) { + // expected-error@+1 {{'hlfir.sum' op result rank must be one less than ARRAY}} + %0 = hlfir.sum %arg0 %arg1, %arg2 : (!hlfir.expr, i32, !fir.box>) -> !hlfir.expr +} diff --git a/flang/test/HLFIR/sum.fir b/flang/test/HLFIR/sum.fir new file mode 100644 --- /dev/null +++ b/flang/test/HLFIR/sum.fir @@ -0,0 +1,179 @@ +// Test hlfir.sum operation parse, verify (no errors), and unparse + +// RUN: fir-opt %s | fir-opt | FileCheck %s + +// array is an expression of known shape +func.func @sum0(%arg0: !hlfir.expr<42xi32>) { + %mask = fir.alloca !fir.logical<4> + %c_1 = arith.constant 1 : index + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %c_1, %mask_box : (!hlfir.expr<42xi32>, index, !fir.box>) -> !hlfir.expr + return +} +// CHECK: func.func @sum0(%[[ARRAY:.*]]: !hlfir.expr<42xi32>) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[C1]], %[[BOX]] : (!hlfir.expr<42xi32>, index, !fir.box>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// array is an expression of assumed shape +func.func @sum1(%arg0: !hlfir.expr) { + %mask = fir.alloca !fir.logical<4> + %c_1 = arith.constant 1 : index + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %c_1, %mask_box : (!hlfir.expr, index, !fir.box>) -> !hlfir.expr + return +} +// CHECK: func.func @sum1(%[[ARRAY:.*]]: !hlfir.expr) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY:.*]] %[[C1]], %[[BOX]] : (!hlfir.expr, index, !fir.box>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// boxed array +func.func @sum2(%arg0: !fir.box>) { + %mask = fir.alloca !fir.logical<4> + %c_1 = arith.constant 1 : index + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %c_1, %mask_box : (!fir.box>, index, !fir.box>) -> !hlfir.expr + return +} +// CHECK: func.func @sum2(%[[ARRAY:.*]]: !fir.box>) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY:.*]] %[[C1]], %[[BOX]] : (!fir.box>, index, !fir.box>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// assumed shape boxed array +func.func @sum3(%arg0: !fir.box>) { + %mask = fir.alloca !fir.logical<4> + %c_1 = arith.constant 1 : index + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %c_1, %mask_box : (!fir.box>, index, !fir.box>) -> !hlfir.expr + return +} +// CHECK: func.func @sum3(%[[ARRAY:.*]]: !fir.box>) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY:.*]] %[[C1]], %[[BOX]] : (!fir.box>, index, !fir.box>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// known shape expr mask +func.func @sum4(%arg0: !fir.box>, %arg1: !hlfir.expr<42x!fir.logical<4>>) { + %c_1 = arith.constant 1 : index + %0 = hlfir.sum %arg0 %c_1, %arg1 : (!fir.box>, index, !hlfir.expr<42x!fir.logical<4>>) -> !hlfir.expr + return +} +// CHECK: func.func @sum4(%[[ARRAY:.*]]: !fir.box>, %[[MASK:.*]]: !hlfir.expr<42x!fir.logical<4>>) { +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[C1]], %[[MASK]] : (!fir.box>, index, !hlfir.expr<42x!fir.logical<4>>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// assumed shape expr mask +func.func @sum5(%arg0: !fir.box>, %arg1: !hlfir.expr>) { + %c_1 = arith.constant 1 : index + %0 = hlfir.sum %arg0 %c_1, %arg1 : (!fir.box>, index, !hlfir.expr>) -> !hlfir.expr + return +} +// CHECK: func.func @sum5(%[[ARRAY:.*]]: !fir.box>, %[[MASK:.*]]: !hlfir.expr>) { +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[C1]], %[[MASK]] : (!fir.box>, index, !hlfir.expr>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// known shape array mask +func.func @sum6(%arg0: !fir.box>, %arg1: !fir.box>>) { + %c_1 = arith.constant 1 : index + %0 = hlfir.sum %arg0 %c_1, %arg1 : (!fir.box>, index, !fir.box>>) -> !hlfir.expr + return +} +// CHECK: func.func @sum6(%[[ARRAY:.*]]: !fir.box>, %[[MASK:.*]]: !fir.box>>) { +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[C1]], %[[MASK]] : (!fir.box>, index, !fir.box>>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// assumed shape array mask +func.func @sum7(%arg0: !fir.box>, %arg1: !fir.box>>) { + %c_1 = arith.constant 1 : index + %0 = hlfir.sum %arg0 %c_1, %arg1 : (!fir.box>, index, !fir.box>>) -> !hlfir.expr + return +} +// CHECK: func.func @sum7(%[[ARRAY:.*]]: !fir.box>, %[[MASK:.*]]: !fir.box>>) { +// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[C1]], %[[MASK]] : (!fir.box>, index, !fir.box>>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: } + +// known shape expr return +func.func @sum8(%arg0: !fir.box>, %arg1: i32) { + %mask = fir.alloca !fir.logical<4> + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %arg1, %mask_box : (!fir.box>, i32, !fir.box>) -> !hlfir.expr<2xi32> + return +} +// CHECK: func.func @sum8(%[[ARRAY:.*]]: !fir.box>, %[[DIM:.*]]: i32) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[DIM]], %[[BOX]] : (!fir.box>, i32, !fir.box>) -> !hlfir.expr<2xi32> +// CHECK-NEXT: return +// CHECK-NEXT: } + +// assumed shape expr return +func.func @sum9(%arg0: !fir.box>, %arg1: i32) { + %mask = fir.alloca !fir.logical<4> + %true = arith.constant true + %true_logical = fir.convert %true : (i1) -> !fir.logical<4> + fir.store %true_logical to %mask : !fir.ref> + %mask_box = fir.embox %mask : (!fir.ref>) -> !fir.box> + %0 = hlfir.sum %arg0 %arg1, %mask_box : (!fir.box>, i32, !fir.box>) -> !hlfir.expr + return +} +// CHECK: func.func @sum9(%[[ARRAY:.*]]: !fir.box>, %[[DIM:.*]]: i32) { +// CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4> +// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true +// CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4> +// CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref> +// CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref>) -> !fir.box> +// CHECK-NEXT: hlfir.sum %[[ARRAY]] %[[DIM]], %[[BOX]] : (!fir.box>, i32, !fir.box>) -> !hlfir.expr +// CHECK-NEXT: return +// CHECK-NEXT: }