Index: flang/lib/Lower/ConvertExpr.cpp =================================================================== --- flang/lib/Lower/ConvertExpr.cpp +++ flang/lib/Lower/ConvertExpr.cpp @@ -332,14 +332,10 @@ } // An expression with non-zero rank is an array expression. -template -static bool isArray(const A &x) { - return x.Rank() != 0; -} +template static bool isArray(const A &x) { return x.Rank() != 0; } /// Is this a variable wrapped in parentheses? -template -static bool isParenthesizedVariable(const A &) { +template static bool isParenthesizedVariable(const A &) { return false; } template @@ -604,8 +600,7 @@ return *mutableBox; } - template - ExtValue genMutableBoxValueImpl(const T &) { + template ExtValue genMutableBoxValueImpl(const T &) { // NULL() case should not be handled here. fir::emitFatalError(getLoc(), "NULL() must be lowered in its context"); } @@ -661,8 +656,7 @@ mlir::Location getLoc() { return location; } - template - mlir::Value genunbox(const A &expr) { + template mlir::Value genunbox(const A &expr) { ExtValue e = genval(expr); if (const fir::UnboxedValue *r = e.getUnboxed()) return *r; @@ -1100,8 +1094,7 @@ return builder.create(getLoc(), lhs, rhs); } - template - mlir::Value createBinaryOp(const A &ex) { + template mlir::Value createBinaryOp(const A &ex) { ExtValue left = genval(ex.left()); return createBinaryOp(left, genval(ex.right())); } @@ -1304,8 +1297,7 @@ return fir::substBase(input, newBase); } - template - ExtValue genval(const Fortran::evaluate::Not &op) { + template ExtValue genval(const Fortran::evaluate::Not &op) { mlir::Value logical = genunbox(op.left()); mlir::Value one = genBoolConstant(true); mlir::Value val = @@ -2176,8 +2168,7 @@ operands, stmtCtx); } - template - bool isCharacterType(const A &exp) { + template bool isCharacterType(const A &exp) { if (auto type = exp.GetType()) return type->category() == Fortran::common::TypeCategory::Character; return false; @@ -3198,16 +3189,10 @@ return genProcedureRef(procRef, resTy); } - template - bool isScalar(const A &x) { - return x.Rank() == 0; - } + template bool isScalar(const A &x) { return x.Rank() == 0; } /// Helper to detect Transformational function reference. - template - bool isTransformationalRef(const T &) { - return false; - } + template bool isTransformationalRef(const T &) { return false; } template bool isTransformationalRef(const Fortran::evaluate::FunctionRef &funcRef) { return !funcRef.IsElemental() && funcRef.Rank(); @@ -3218,8 +3203,7 @@ expr.u); } - template - ExtValue asArray(const A &x) { + template ExtValue asArray(const A &x) { return Fortran::lower::createSomeArrayTempValue(converter, toEvExpr(x), symMap, stmtCtx); } @@ -3242,15 +3226,13 @@ return Fortran::lower::createBoxValue(getLoc(), converter, someExpr, symMap, stmtCtx); } - template - ExtValue asArrayArg(const A &, const B &x) { + template ExtValue asArrayArg(const A &, const B &x) { // If the expression to pass as an argument is not a designator, then create // an array temp. return asArray(x); } - template - ExtValue gen(const Fortran::evaluate::Expr &x) { + template ExtValue gen(const Fortran::evaluate::Expr &x) { // Whole array symbols or components, and results of transformational // functions already have a storage and the scalar expression lowering path // is used to not create a new temporary storage. @@ -3262,8 +3244,7 @@ return asArrayArg(x); return asArray(x); } - template - ExtValue genval(const Fortran::evaluate::Expr &x) { + template ExtValue genval(const Fortran::evaluate::Expr &x) { if (isScalar(x) || Fortran::evaluate::UnwrapWholeSymbolDataRef(x) || inInitializer) return std::visit([&](const auto &e) { return genval(e); }, x.u); @@ -3288,8 +3269,7 @@ ExtValue genref(const A &a) { return gen(a); } - template - ExtValue genref(const A &a) { + template ExtValue genref(const A &a) { if (inInitializer) { // Initialization expressions can never allocate memory. return genval(a); @@ -4112,6 +4092,7 @@ return adjustedArrayElementType(pathTy); } + /// Lower rhs of an array expression. ExtValue lowerArrayExpression(const Fortran::lower::SomeExpr &exp) { mlir::Type resTy = converter.genType(exp); return std::visit( @@ -4666,8 +4647,7 @@ //===--------------------------------------------------------------------===// /// Lower the expression, \p x, in a scalar context. - template - ExtValue asScalar(const A &x) { + template ExtValue asScalar(const A &x) { return ScalarExprLowering{getLoc(), converter, symMap, stmtCtx}.genval(x); } @@ -4675,16 +4655,14 @@ /// space, the expression may be scalar and refer to an array. We want to /// raise the array access to array operations in FIR to analyze potential /// conflicts even when the result is a scalar element. - template - ExtValue asScalarArray(const A &x) { + template ExtValue asScalarArray(const A &x) { return explicitSpaceIsActive() && !isPointerAssignment() ? genarr(x)(IterationSpace{}) : asScalar(x); } /// Lower the expression in a scalar context to a memory reference. - template - ExtValue asScalarRef(const A &x) { + template ExtValue asScalarRef(const A &x) { return ScalarExprLowering{getLoc(), converter, symMap, stmtCtx}.gen(x); } @@ -4692,8 +4670,7 @@ /// a nullptr (because this is an absent optional or unallocated/disassociated /// descriptor). The returned expression cannot be addressed directly, it is /// meant to inquire about its status before addressing the related entity. - template - ExtValue asInquired(const A &x) { + template ExtValue asInquired(const A &x) { return ScalarExprLowering{getLoc(), converter, symMap, stmtCtx} .lowerIntrinsicArgumentAsInquired(x); } @@ -4722,8 +4699,7 @@ /// Lower an elemental function array argument. This ensures array /// sub-expressions that are not variables and must be passed by address /// are lowered by value and placed in memory. - template - CC genElementalArgument(const A &x) { + template CC genElementalArgument(const A &x) { // Ensure the returned element is in memory if this is what was requested. if ((semant == ConstituentSemantics::RefOpaque || semant == ConstituentSemantics::DataAddr || @@ -5066,8 +5042,7 @@ "array procedure reference with alt-return"); return genProcRef(x, llvm::None); } - template - CC genScalarAndForwardValue(const A &x) { + template CC genScalarAndForwardValue(const A &x) { ExtValue result = asScalar(x); return [=](IterSpace) { return result; }; } @@ -5077,12 +5052,17 @@ return genScalarAndForwardValue(x); } - template - CC genarr(const Fortran::evaluate::Expr &x) { + template CC genarr(const Fortran::evaluate::Expr &x) { LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump(llvm::dbgs(), x)); - if (isArray(x) || explicitSpaceIsActive() || + if (isArray(x) || (explicitSpaceIsActive() && isLeftHandSide()) || isElementalProcWithArrayArgs(x)) return std::visit([&](const auto &e) { return genarr(e); }, x.u); + if (explicitSpaceIsActive()) { + assert(!isArray(x) && !isLeftHandSide()); + auto cc = std::visit([&](const auto &e) { return genarr(e); }, x.u); + auto result = cc(IterationSpace{}); + return [=](IterSpace) { return result; }; + } return genScalarAndForwardValue(x); } @@ -5135,8 +5115,7 @@ }; } - template - CC genarr(const Fortran::evaluate::Parentheses &x) { + template CC genarr(const Fortran::evaluate::Parentheses &x) { mlir::Location loc = getLoc(); if (isReferentiallyOpaque()) { // Context is a call argument in, for example, an elemental procedure @@ -5190,8 +5169,7 @@ // Binary elemental ops //===--------------------------------------------------------------------===// - template - CC createBinaryOp(const A &evEx) { + template CC createBinaryOp(const A &evEx) { mlir::Location loc = getLoc(); auto lambda = genarr(evEx.left()); auto rf = genarr(evEx.right()); @@ -5289,8 +5267,7 @@ } /// Fortran's concatenation operator `//`. - template - CC genarr(const Fortran::evaluate::Concat &x) { + template CC genarr(const Fortran::evaluate::Concat &x) { mlir::Location loc = getLoc(); auto lf = genarr(x.left()); auto rf = genarr(x.right()); @@ -5308,8 +5285,7 @@ }; } - template - CC genarr(const Fortran::evaluate::SetLength &x) { + template CC genarr(const Fortran::evaluate::SetLength &x) { auto lf = genarr(x.left()); mlir::Value rhs = fir::getBase(asScalar(x.right())); return [=](IterSpace iters) -> ExtValue { @@ -5318,9 +5294,8 @@ }; } - template - CC genarr(const Fortran::evaluate::Constant &x) { - if (/*explicitSpaceIsActive() &&*/ x.Rank() == 0) + template CC genarr(const Fortran::evaluate::Constant &x) { + if (x.Rank() == 0) return genScalarAndForwardValue(x); mlir::Location loc = getLoc(); mlir::IndexType idxTy = builder.getIndexType(); @@ -5442,15 +5417,13 @@ return fir::factory::readExtent(builder, getLoc(), x, dim); } - template - ExtValue genArrayBase(const A &base) { + template ExtValue genArrayBase(const A &base) { ScalarExprLowering sel{getLoc(), converter, symMap, stmtCtx}; return base.IsSymbol() ? sel.gen(getFirstSym(base)) : sel.gen(base.GetComponent()); } - template - bool hasEvArrayRef(const A &x) { + template bool hasEvArrayRef(const A &x) { struct HasEvArrayRefHelper : public Fortran::evaluate::AnyTraverse { HasEvArrayRefHelper() @@ -6072,8 +6045,7 @@ return genarr(x.complex(), components); } - template - CC genSlicePath(const A &x, ComponentPath &components) { + template CC genSlicePath(const A &x, ComponentPath &components) { return genarr(x, components); } @@ -6523,8 +6495,7 @@ // LOCICAL operators (.NOT., .AND., .EQV., etc.) //===--------------------------------------------------------------------===// - template - CC genarr(const Fortran::evaluate::Not &x) { + template CC genarr(const Fortran::evaluate::Not &x) { mlir::Location loc = getLoc(); mlir::IntegerType i1Ty = builder.getI1Type(); auto lambda = genarr(x.left()); @@ -6535,8 +6506,7 @@ return builder.create(loc, val, truth); }; } - template - CC createBinaryBoolOp(const A &x) { + template CC createBinaryBoolOp(const A &x) { mlir::Location loc = getLoc(); mlir::IntegerType i1Ty = builder.getI1Type(); auto lf = genarr(x.left()); @@ -6634,8 +6604,7 @@ return std::visit([&](const auto &x) { return genarr(x); }, r.u); } - template - CC genarr(const Fortran::evaluate::Designator &des) { + template CC genarr(const Fortran::evaluate::Designator &des) { ComponentPath components(des.Rank() > 0); return std::visit([&](const auto &x) { return genarr(x, components); }, des.u); @@ -6994,8 +6963,7 @@ return genImplicitArrayAccess(x.GetComponent(), components); } - template - CC genAsScalar(const A &x) { + template CC genAsScalar(const A &x) { mlir::Location loc = getLoc(); if (isProjectedCopyInCopyOut()) { return [=, &x, builder = &converter.getFirOpBuilder()]( @@ -7183,6 +7151,12 @@ return semant == ConstituentSemantics::CustomCopyInCopyOut; } + /// Are we lowering in a left-hand side context? + inline bool isLeftHandSide() { + return isCopyInCopyOut() || isProjectedCopyInCopyOut() || + isCustomCopyInCopyOut(); + } + /// Array appears in a context where it must be boxed. inline bool isBoxValue() { return semant == ConstituentSemantics::BoxValue; } Index: flang/test/Lower/forall/array-constructor.f90 =================================================================== --- /dev/null +++ flang/test/Lower/forall/array-constructor.f90 @@ -0,0 +1,284 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +subroutine ac1(arr,n) + integer :: arr(:), n + forall (i=1:n:2) + arr(i:i+2) = func((/i/)) + end forall +contains + pure integer function func(a) + integer, intent(in) :: a(:) + func = a(1) + end function func +end subroutine ac1 + +! CHECK-LABEL: func @_QPac1( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.box> {fir.bindc_name = "arr"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "n"}) { +! CHECK: %[[VAL_2:.*]] = fir.alloca index {bindc_name = ".buff.pos"} +! CHECK: %[[VAL_3:.*]] = fir.alloca index {bindc_name = ".buff.size"} +! CHECK: %[[VAL_4:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"} +! CHECK: %[[VAL_5:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> index +! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_1]] : !fir.ref +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> index +! CHECK: %[[VAL_9:.*]] = arith.constant 2 : i32 +! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i32) -> index +! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_0]] : (!fir.box>) -> !fir.array +! CHECK: %[[VAL_12:.*]] = fir.do_loop %[[VAL_13:.*]] = %[[VAL_6]] to %[[VAL_8]] step %[[VAL_10]] unordered iter_args(%[[VAL_14:.*]] = %[[VAL_11]]) -> (!fir.array) { +! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_13]] : (index) -> i32 +! CHECK: fir.store %[[VAL_15]] to %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> i64 +! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i64) -> index +! CHECK: %[[VAL_20:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index +! CHECK: %[[VAL_22:.*]] = fir.load %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_23:.*]] = arith.constant 2 : i32 +! CHECK: %[[VAL_24:.*]] = arith.addi %[[VAL_22]], %[[VAL_23]] : i32 +! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i32) -> i64 +! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i64) -> index +! CHECK: %[[VAL_27:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_28:.*]] = arith.subi %[[VAL_26]], %[[VAL_19]] : index +! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_28]], %[[VAL_21]] : index +! CHECK: %[[VAL_30:.*]] = arith.divsi %[[VAL_29]], %[[VAL_21]] : index +! CHECK: %[[VAL_31:.*]] = arith.cmpi sgt, %[[VAL_30]], %[[VAL_27]] : index +! CHECK: %[[VAL_32:.*]] = arith.select %[[VAL_31]], %[[VAL_30]], %[[VAL_27]] : index +! CHECK: %[[VAL_33:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_34:.*]] = arith.constant 0 : index +! CHECK: fir.store %[[VAL_34]] to %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_35:.*]] = fir.allocmem !fir.array<1xi32> +! CHECK: %[[VAL_36:.*]] = arith.constant 1 : index +! CHECK: fir.store %[[VAL_36]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_37:.*]] = fir.load %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_38:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_39:.*]] = fir.zero_bits !fir.ref> +! CHECK: %[[VAL_40:.*]] = fir.coordinate_of %[[VAL_39]], %[[VAL_38]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (!fir.ref) -> index +! CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_43:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_44:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_45:.*]] = arith.addi %[[VAL_42]], %[[VAL_44]] : index +! CHECK: %[[VAL_46:.*]] = arith.cmpi sle, %[[VAL_43]], %[[VAL_45]] : index +! CHECK: %[[VAL_47:.*]] = fir.if %[[VAL_46]] -> (!fir.heap>) { +! CHECK: %[[VAL_48:.*]] = arith.constant 2 : index +! CHECK: %[[VAL_49:.*]] = arith.muli %[[VAL_45]], %[[VAL_48]] : index +! CHECK: fir.store %[[VAL_49]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_50:.*]] = arith.muli %[[VAL_49]], %[[VAL_41]] : index +! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_35]] : (!fir.heap>) -> !fir.ref +! CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_50]] : (index) -> i64 +! CHECK: %[[VAL_53:.*]] = fir.call @realloc(%[[VAL_51]], %[[VAL_52]]) : (!fir.ref, i64) -> !fir.ref +! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (!fir.ref) -> !fir.heap> +! CHECK: fir.result %[[VAL_54]] : !fir.heap> +! CHECK: } else { +! CHECK: fir.result %[[VAL_35]] : !fir.heap> +! CHECK: } +! CHECK: %[[VAL_55:.*]] = fir.coordinate_of %[[VAL_56:.*]], %[[VAL_42]] : (!fir.heap>, index) -> !fir.ref +! CHECK: fir.store %[[VAL_37]] to %[[VAL_55]] : !fir.ref +! CHECK: fir.store %[[VAL_45]] to %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_57:.*]] = fir.load %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_58:.*]] = fir.shape %[[VAL_57]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_59:.*]] = fir.array_load %[[VAL_56]](%[[VAL_58]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array<1xi32> +! CHECK: %[[VAL_60:.*]] = fir.allocmem !fir.array<1xi32> +! CHECK: %[[VAL_61:.*]] = fir.shape %[[VAL_33]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_62:.*]] = fir.array_load %[[VAL_60]](%[[VAL_61]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array<1xi32> +! CHECK: %[[VAL_63:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_64:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_65:.*]] = arith.subi %[[VAL_33]], %[[VAL_63]] : index +! CHECK: %[[VAL_66:.*]] = fir.do_loop %[[VAL_67:.*]] = %[[VAL_64]] to %[[VAL_65]] step %[[VAL_63]] unordered iter_args(%[[VAL_68:.*]] = %[[VAL_62]]) -> (!fir.array<1xi32>) { +! CHECK: %[[VAL_69:.*]] = fir.array_fetch %[[VAL_59]], %[[VAL_67]] : (!fir.array<1xi32>, index) -> i32 +! CHECK: %[[VAL_70:.*]] = fir.array_update %[[VAL_68]], %[[VAL_69]], %[[VAL_67]] : (!fir.array<1xi32>, i32, index) -> !fir.array<1xi32> +! CHECK: fir.result %[[VAL_70]] : !fir.array<1xi32> +! CHECK: } +! CHECK: fir.array_merge_store %[[VAL_62]], %[[VAL_71:.*]] to %[[VAL_60]] : !fir.array<1xi32>, !fir.array<1xi32>, !fir.heap> +! CHECK: %[[VAL_72:.*]] = fir.shape %[[VAL_33]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_73:.*]] = fir.embox %[[VAL_60]](%[[VAL_72]]) : (!fir.heap>, !fir.shape<1>) -> !fir.box> +! CHECK: %[[VAL_74:.*]] = fir.convert %[[VAL_73]] : (!fir.box>) -> !fir.box> +! CHECK: %[[VAL_75:.*]] = fir.call @_QFac1Pfunc(%[[VAL_74]]) : (!fir.box>) -> i32 +! CHECK: %[[VAL_76:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_77:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_78:.*]] = arith.subi %[[VAL_32]], %[[VAL_76]] : index +! CHECK: %[[VAL_79:.*]] = fir.do_loop %[[VAL_80:.*]] = %[[VAL_77]] to %[[VAL_78]] step %[[VAL_76]] unordered iter_args(%[[VAL_81:.*]] = %[[VAL_14]]) -> (!fir.array) { +! CHECK: %[[VAL_82:.*]] = arith.subi %[[VAL_19]], %[[VAL_16]] : index +! CHECK: %[[VAL_83:.*]] = arith.muli %[[VAL_80]], %[[VAL_21]] : index +! CHECK: %[[VAL_84:.*]] = arith.addi %[[VAL_82]], %[[VAL_83]] : index +! CHECK: %[[VAL_85:.*]] = fir.array_update %[[VAL_81]], %[[VAL_75]], %[[VAL_84]] : (!fir.array, i32, index) -> !fir.array +! CHECK: fir.result %[[VAL_85]] : !fir.array +! CHECK: } +! CHECK: fir.freemem %[[VAL_60]] : !fir.heap> +! CHECK: fir.freemem %[[VAL_56]] : !fir.heap> +! CHECK: fir.result %[[VAL_86:.*]] : !fir.array +! CHECK: } +! CHECK: fir.array_merge_store %[[VAL_11]], %[[VAL_87:.*]] to %[[VAL_0]] : !fir.array, !fir.array, !fir.box> +! CHECK: return +! CHECK: } + +! CHECK-LABEL: func @_QFac1Pfunc( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.box> {fir.bindc_name = "a"}) -> i32 { +! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "func", uniq_name = "_QFfuncEfunc"} +! CHECK: %[[VAL_2:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_3:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_4:.*]] = arith.subi %[[VAL_2]], %[[VAL_3]] : i64 +! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_4]] : (!fir.box>, i64) -> !fir.ref +! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref +! CHECK: fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref +! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_1]] : !fir.ref +! CHECK: return %[[VAL_7]] : i32 +! CHECK: } + +subroutine ac2(arr,n) + integer :: arr(:), n + forall (i=1:n:2) + arr(i:i+2) = func((/i/)) + end forall +contains + pure function func(a) + integer :: func(3) + integer, intent(in) :: a(:) + func = a(1:3) + end function func +end subroutine ac2 + +! CHECK-LABEL: func @_QPac2( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.box> {fir.bindc_name = "arr"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "n"}) { +! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.array<3xi32> {bindc_name = ".result"} +! CHECK: %[[VAL_3:.*]] = fir.alloca index {bindc_name = ".buff.pos"} +! CHECK: %[[VAL_4:.*]] = fir.alloca index {bindc_name = ".buff.size"} +! CHECK: %[[VAL_5:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"} +! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i32) -> index +! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref +! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i32) -> index +! CHECK: %[[VAL_10:.*]] = arith.constant 2 : i32 +! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i32) -> index +! CHECK: %[[VAL_12:.*]] = fir.array_load %[[VAL_0]] : (!fir.box>) -> !fir.array +! CHECK: %[[VAL_13:.*]] = fir.do_loop %[[VAL_14:.*]] = %[[VAL_7]] to %[[VAL_9]] step %[[VAL_11]] unordered iter_args(%[[VAL_15:.*]] = %[[VAL_12]]) -> (!fir.array) { +! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_14]] : (index) -> i32 +! CHECK: fir.store %[[VAL_16]] to %[[VAL_5]] : !fir.ref +! CHECK: %[[VAL_17:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_5]] : !fir.ref +! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i32) -> i64 +! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i64) -> index +! CHECK: %[[VAL_21:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (i64) -> index +! CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_5]] : !fir.ref +! CHECK: %[[VAL_24:.*]] = arith.constant 2 : i32 +! CHECK: %[[VAL_25:.*]] = arith.addi %[[VAL_23]], %[[VAL_24]] : i32 +! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64 +! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index +! CHECK: %[[VAL_28:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_29:.*]] = arith.subi %[[VAL_27]], %[[VAL_20]] : index +! CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_29]], %[[VAL_22]] : index +! CHECK: %[[VAL_31:.*]] = arith.divsi %[[VAL_30]], %[[VAL_22]] : index +! CHECK: %[[VAL_32:.*]] = arith.cmpi sgt, %[[VAL_31]], %[[VAL_28]] : index +! CHECK: %[[VAL_33:.*]] = arith.select %[[VAL_32]], %[[VAL_31]], %[[VAL_28]] : index +! CHECK: %[[VAL_34:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_35:.*]] = arith.constant 0 : index +! CHECK: fir.store %[[VAL_35]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_36:.*]] = fir.allocmem !fir.array<1xi32> +! CHECK: %[[VAL_37:.*]] = arith.constant 1 : index +! CHECK: fir.store %[[VAL_37]] to %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_5]] : !fir.ref +! CHECK: %[[VAL_39:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_40:.*]] = fir.zero_bits !fir.ref> +! CHECK: %[[VAL_41:.*]] = fir.coordinate_of %[[VAL_40]], %[[VAL_39]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (!fir.ref) -> index +! CHECK: %[[VAL_43:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_45:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_46:.*]] = arith.addi %[[VAL_43]], %[[VAL_45]] : index +! CHECK: %[[VAL_47:.*]] = arith.cmpi sle, %[[VAL_44]], %[[VAL_46]] : index +! CHECK: %[[VAL_48:.*]] = fir.if %[[VAL_47]] -> (!fir.heap>) { +! CHECK: %[[VAL_49:.*]] = arith.constant 2 : index +! CHECK: %[[VAL_50:.*]] = arith.muli %[[VAL_46]], %[[VAL_49]] : index +! CHECK: fir.store %[[VAL_50]] to %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_51:.*]] = arith.muli %[[VAL_50]], %[[VAL_42]] : index +! CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_36]] : (!fir.heap>) -> !fir.ref +! CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_51]] : (index) -> i64 +! CHECK: %[[VAL_54:.*]] = fir.call @realloc(%[[VAL_52]], %[[VAL_53]]) : (!fir.ref, i64) -> !fir.ref +! CHECK: %[[VAL_55:.*]] = fir.convert %[[VAL_54]] : (!fir.ref) -> !fir.heap> +! CHECK: fir.result %[[VAL_55]] : !fir.heap> +! CHECK: } else { +! CHECK: fir.result %[[VAL_36]] : !fir.heap> +! CHECK: } +! CHECK: %[[VAL_56:.*]] = fir.coordinate_of %[[VAL_57:.*]], %[[VAL_43]] : (!fir.heap>, index) -> !fir.ref +! CHECK: fir.store %[[VAL_38]] to %[[VAL_56]] : !fir.ref +! CHECK: fir.store %[[VAL_46]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_58:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_59:.*]] = fir.shape %[[VAL_58]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_60:.*]] = fir.array_load %[[VAL_57]](%[[VAL_59]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array<1xi32> +! CHECK: %[[VAL_61:.*]] = fir.allocmem !fir.array<1xi32> +! CHECK: %[[VAL_62:.*]] = fir.shape %[[VAL_34]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_63:.*]] = fir.array_load %[[VAL_61]](%[[VAL_62]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array<1xi32> +! CHECK: %[[VAL_64:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_65:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_66:.*]] = arith.subi %[[VAL_34]], %[[VAL_64]] : index +! CHECK: %[[VAL_67:.*]] = fir.do_loop %[[VAL_68:.*]] = %[[VAL_65]] to %[[VAL_66]] step %[[VAL_64]] unordered iter_args(%[[VAL_69:.*]] = %[[VAL_63]]) -> (!fir.array<1xi32>) { +! CHECK: %[[VAL_70:.*]] = fir.array_fetch %[[VAL_60]], %[[VAL_68]] : (!fir.array<1xi32>, index) -> i32 +! CHECK: %[[VAL_71:.*]] = fir.array_update %[[VAL_69]], %[[VAL_70]], %[[VAL_68]] : (!fir.array<1xi32>, i32, index) -> !fir.array<1xi32> +! CHECK: fir.result %[[VAL_71]] : !fir.array<1xi32> +! CHECK: } +! CHECK: fir.array_merge_store %[[VAL_63]], %[[VAL_72:.*]] to %[[VAL_61]] : !fir.array<1xi32>, !fir.array<1xi32>, !fir.heap> +! CHECK: %[[VAL_73:.*]] = fir.shape %[[VAL_34]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_74:.*]] = fir.embox %[[VAL_61]](%[[VAL_73]]) : (!fir.heap>, !fir.shape<1>) -> !fir.box> +! CHECK: %[[VAL_75:.*]] = arith.constant 3 : i64 +! CHECK: %[[VAL_76:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_77:.*]] = arith.subi %[[VAL_75]], %[[VAL_76]] : i64 +! CHECK: %[[VAL_78:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_79:.*]] = arith.addi %[[VAL_77]], %[[VAL_78]] : i64 +! CHECK: %[[VAL_80:.*]] = fir.convert %[[VAL_79]] : (i64) -> index +! CHECK: %[[VAL_81:.*]] = fir.call @llvm.stacksave() : () -> !fir.ref +! CHECK: %[[VAL_82:.*]] = fir.shape %[[VAL_80]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_83:.*]] = fir.convert %[[VAL_74]] : (!fir.box>) -> !fir.box> +! CHECK: %[[VAL_84:.*]] = fir.call @_QFac2Pfunc(%[[VAL_83]]) : (!fir.box>) -> !fir.array<3xi32> +! CHECK: fir.save_result %[[VAL_84]] to %[[VAL_2]](%[[VAL_82]]) : !fir.array<3xi32>, !fir.ref>, !fir.shape<1> +! CHECK: %[[VAL_85:.*]] = fir.shape %[[VAL_80]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_86:.*]] = fir.array_load %[[VAL_2]](%[[VAL_85]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array<3xi32> +! CHECK: %[[VAL_87:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_88:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_89:.*]] = arith.subi %[[VAL_33]], %[[VAL_87]] : index +! CHECK: %[[VAL_90:.*]] = fir.do_loop %[[VAL_91:.*]] = %[[VAL_88]] to %[[VAL_89]] step %[[VAL_87]] unordered iter_args(%[[VAL_92:.*]] = %[[VAL_15]]) -> (!fir.array) { +! CHECK: %[[VAL_93:.*]] = fir.array_fetch %[[VAL_86]], %[[VAL_91]] : (!fir.array<3xi32>, index) -> i32 +! CHECK: %[[VAL_94:.*]] = arith.subi %[[VAL_20]], %[[VAL_17]] : index +! CHECK: %[[VAL_95:.*]] = arith.muli %[[VAL_91]], %[[VAL_22]] : index +! CHECK: %[[VAL_96:.*]] = arith.addi %[[VAL_94]], %[[VAL_95]] : index +! CHECK: %[[VAL_97:.*]] = fir.array_update %[[VAL_92]], %[[VAL_93]], %[[VAL_96]] : (!fir.array, i32, index) -> !fir.array +! CHECK: fir.result %[[VAL_97]] : !fir.array +! CHECK: } +! CHECK: fir.call @llvm.stackrestore(%[[VAL_81]]) : (!fir.ref) -> () +! CHECK: fir.freemem %[[VAL_61]] : !fir.heap> +! CHECK: fir.freemem %[[VAL_57]] : !fir.heap> +! CHECK: fir.result %[[VAL_98:.*]] : !fir.array +! CHECK: } +! CHECK: fir.array_merge_store %[[VAL_12]], %[[VAL_99:.*]] to %[[VAL_0]] : !fir.array, !fir.array, !fir.box> +! CHECK: return +! CHECK: } + +! CHECK-LABEL: func @_QFac2Pfunc( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.box> {fir.bindc_name = "a"}) -> !fir.array<3xi32> { +! CHECK: %[[VAL_1:.*]] = arith.constant 3 : index +! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.array<3xi32> {bindc_name = "func", uniq_name = "_QFfuncEfunc"} +! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_4:.*]] = fir.array_load %[[VAL_2]](%[[VAL_3]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array<3xi32> +! CHECK: %[[VAL_5:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i64) -> index +! CHECK: %[[VAL_7:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index +! CHECK: %[[VAL_9:.*]] = arith.constant 3 : i64 +! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i64) -> index +! CHECK: %[[VAL_11:.*]] = fir.slice %[[VAL_6]], %[[VAL_10]], %[[VAL_8]] : (index, index, index) -> !fir.slice<1> +! CHECK: %[[VAL_12:.*]] = fir.array_load %[[VAL_0]] {{\[}}%[[VAL_11]]] : (!fir.box>, !fir.slice<1>) -> !fir.array +! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_14:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_1]], %[[VAL_13]] : index +! CHECK: %[[VAL_16:.*]] = fir.do_loop %[[VAL_17:.*]] = %[[VAL_14]] to %[[VAL_15]] step %[[VAL_13]] unordered iter_args(%[[VAL_18:.*]] = %[[VAL_4]]) -> (!fir.array<3xi32>) { +! CHECK: %[[VAL_19:.*]] = fir.array_fetch %[[VAL_12]], %[[VAL_17]] : (!fir.array, index) -> i32 +! CHECK: %[[VAL_20:.*]] = fir.array_update %[[VAL_18]], %[[VAL_19]], %[[VAL_17]] : (!fir.array<3xi32>, i32, index) -> !fir.array<3xi32> +! CHECK: fir.result %[[VAL_20]] : !fir.array<3xi32> +! CHECK: } +! CHECK: fir.array_merge_store %[[VAL_4]], %[[VAL_21:.*]] to %[[VAL_2]] : !fir.array<3xi32>, !fir.array<3xi32>, !fir.ref> +! CHECK: %[[VAL_22:.*]] = fir.load %[[VAL_2]] : !fir.ref> +! CHECK: return %[[VAL_22]] : !fir.array<3xi32> +! CHECK: } Index: flang/test/Lower/forall/forall-2.f90 =================================================================== --- flang/test/Lower/forall/forall-2.f90 +++ flang/test/Lower/forall/forall-2.f90 @@ -131,13 +131,13 @@ ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i32) -> i64 ! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (i64) -> index ! CHECK: %[[VAL_32:.*]] = arith.subi %[[VAL_31]], %[[VAL_15]] : index +! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_0]] : !fir.ref +! CHECK: %[[VAL_40:.*]] = arith.constant 0 : i32 +! CHECK: %[[VAL_41:.*]] = arith.subi %[[VAL_40]], %[[VAL_39]] : i32 ! CHECK: %[[VAL_33:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_34:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_35:.*]] = arith.subi %[[VAL_28]], %[[VAL_33]] : index ! CHECK: %[[VAL_36:.*]] = fir.do_loop %[[VAL_37:.*]] = %[[VAL_34]] to %[[VAL_35]] step %[[VAL_33]] unordered iter_args(%[[VAL_38:.*]] = %[[VAL_13]]) -> (!fir.array<10x10xi32>) { -! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_40:.*]] = arith.constant 0 : i32 -! CHECK: %[[VAL_41:.*]] = arith.subi %[[VAL_40]], %[[VAL_39]] : i32 ! CHECK: %[[VAL_42:.*]] = arith.subi %[[VAL_17]], %[[VAL_15]] : index ! CHECK: %[[VAL_43:.*]] = arith.muli %[[VAL_37]], %[[VAL_19]] : index ! CHECK: %[[VAL_44:.*]] = arith.addi %[[VAL_42]], %[[VAL_43]] : index @@ -174,9 +174,8 @@ ! CHECK: %[[VAL_13:.*]] = fir.do_loop %[[VAL_14:.*]] = %[[VAL_7]] to %[[VAL_9]] step %[[VAL_10]] unordered iter_args(%[[VAL_15:.*]] = %[[VAL_12]]) -> (!fir.array<1xi32>) { ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_14]] : (index) -> i32 ! CHECK: fir.store %[[VAL_16]] to %[[VAL_2]] : !fir.ref -! CHECK: %[[VAL_17:.*]] = arith.constant 1 : i32 -! CHECK: %[[VAL_18:.*]] = arith.constant 1 : index -! CHECK: %[[VAL_19:.*]] = arith.constant 1 : i64 +! CHECK-DAG: %[[VAL_18:.*]] = arith.constant 1 : index +! CHECK-DAG: %[[VAL_19:.*]] = arith.constant 1 : i64 ! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i64) -> index ! CHECK: %[[VAL_21:.*]] = arith.addi %[[VAL_18]], %[[VAL_4]] : index ! CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_21]], %[[VAL_18]] : index @@ -187,6 +186,7 @@ ! CHECK: %[[VAL_27:.*]] = fir.slice %[[VAL_18]], %[[VAL_22]], %[[VAL_20]], %[[VAL_24]], %[[VAL_25]], %[[VAL_25]] : (index, index, index, i64, index, index) -> !fir.slice<2> ! CHECK: %[[VAL_28:.*]] = fir.embox %[[VAL_1]](%[[VAL_26]]) {{\[}}%[[VAL_27]]] : (!fir.ref>, !fir.shape<2>, !fir.slice<2>) -> !fir.box> ! CHECK: %[[VAL_29:.*]] = fir.call @_QPe(%[[VAL_28]]) : (!fir.box>) -> i32 +! CHECK: %[[VAL_17:.*]] = arith.constant 1 : i32 ! CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_29]], %[[VAL_17]] : i32 ! CHECK: %[[VAL_31:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_32:.*]] = fir.load %[[VAL_2]] : !fir.ref Index: flang/test/Lower/forall/forall-construct-2.f90 =================================================================== --- flang/test/Lower/forall/forall-construct-2.f90 +++ flang/test/Lower/forall/forall-construct-2.f90 @@ -52,6 +52,7 @@ ! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i32) -> i64 ! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i64) -> index ! CHECK: %[[VAL_42:.*]] = arith.subi %[[VAL_41]], %[[VAL_34]] : index +! CHECK: %[[VAL_54:.*]] = fir.array_fetch %[[VAL_23]], %[[VAL_38]], %[[VAL_42]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_43:.*]] = arith.constant 1 : index ! CHECK-DAG: %[[VAL_44:.*]] = fir.load %[[VAL_5]] : !fir.ref ! CHECK-DAG: %[[VAL_45:.*]] = arith.constant 1 : i32 @@ -63,7 +64,6 @@ ! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_50]] : (i32) -> i64 ! CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_51]] : (i64) -> index ! CHECK: %[[VAL_53:.*]] = arith.subi %[[VAL_52]], %[[VAL_43]] : index -! CHECK: %[[VAL_54:.*]] = fir.array_fetch %[[VAL_23]], %[[VAL_38]], %[[VAL_42]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_55:.*]] = fir.array_fetch %[[VAL_25]], %[[VAL_49]], %[[VAL_53]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_56:.*]] = arith.addf %[[VAL_54]], %[[VAL_55]] : f32 ! CHECK: %[[VAL_57:.*]] = arith.constant 1 : index Index: flang/test/Lower/forall/forall-construct-3.f90 =================================================================== --- flang/test/Lower/forall/forall-construct-3.f90 +++ flang/test/Lower/forall/forall-construct-3.f90 @@ -65,6 +65,7 @@ ! CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_52]] : (i32) -> i64 ! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i64) -> index ! CHECK: %[[VAL_55:.*]] = arith.subi %[[VAL_54]], %[[VAL_47]] : index +! CHECK: %[[VAL_67:.*]] = fir.array_fetch %[[VAL_24]], %[[VAL_51]], %[[VAL_55]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_56:.*]] = arith.constant 1 : index ! CHECK-DAG: %[[VAL_57:.*]] = fir.load %[[VAL_6]] : !fir.ref ! CHECK-DAG: %[[VAL_58:.*]] = arith.constant 1 : i32 @@ -76,7 +77,6 @@ ! CHECK: %[[VAL_64:.*]] = fir.convert %[[VAL_63]] : (i32) -> i64 ! CHECK: %[[VAL_65:.*]] = fir.convert %[[VAL_64]] : (i64) -> index ! CHECK: %[[VAL_66:.*]] = arith.subi %[[VAL_65]], %[[VAL_56]] : index -! CHECK: %[[VAL_67:.*]] = fir.array_fetch %[[VAL_24]], %[[VAL_51]], %[[VAL_55]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_68:.*]] = fir.array_fetch %[[VAL_26]], %[[VAL_62]], %[[VAL_66]] : (!fir.array<200x200xf32>, index, index) -> f32 ! CHECK: %[[VAL_69:.*]] = arith.addf %[[VAL_67]], %[[VAL_68]] : f32 ! CHECK: %[[VAL_70:.*]] = arith.constant 1 : index Index: flang/test/Lower/forall/forall-construct.f90 =================================================================== --- flang/test/Lower/forall/forall-construct.f90 +++ flang/test/Lower/forall/forall-construct.f90 @@ -71,8 +71,8 @@ ! CHECK: %[[VAL_59:.*]] = fir.convert %[[VAL_58]] : (i32) -> i64 ! CHECK: %[[VAL_60:.*]] = fir.convert %[[VAL_59]] : (i64) -> index ! CHECK: %[[VAL_61:.*]] = arith.subi %[[VAL_60]], %[[VAL_53]] : index -! CHECK: %[[VAL_62:.*]] = arith.constant 3.140000e+00 : f32 -! CHECK: %[[VAL_63:.*]] = fir.array_fetch %[[VAL_31]], %[[VAL_57]], %[[VAL_61]] : (!fir.array, index, index) -> f32 +! CHECK-DAG: %[[VAL_62:.*]] = arith.constant 3.140000e+00 : f32 +! CHECK-DAG: %[[VAL_63:.*]] = fir.array_fetch %[[VAL_31]], %[[VAL_57]], %[[VAL_61]] : (!fir.array, index, index) -> f32 ! CHECK: %[[VAL_64:.*]] = arith.divf %[[VAL_63]], %[[VAL_62]] : f32 ! CHECK: %[[VAL_65:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_66:.*]] = fir.load %[[VAL_3]] : !fir.ref Index: flang/test/Lower/forall/forall-ranked.f90 =================================================================== --- flang/test/Lower/forall/forall-ranked.f90 +++ flang/test/Lower/forall/forall-ranked.f90 @@ -40,11 +40,11 @@ ! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i32) -> i64 ! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_36]] : (i64) -> index ! CHECK: %[[VAL_38:.*]] = arith.subi %[[VAL_37]], %[[VAL_16]] : index +! CHECK: %[[VAL_45:.*]] = fir.call @_QPf(%[[VAL_0]]) : (!fir.ref) -> i32 ! CHECK: %[[VAL_39:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_40:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_41:.*]] = arith.subi %[[VAL_31]], %[[VAL_39]] : index ! CHECK: %[[VAL_42:.*]] = fir.do_loop %[[VAL_43:.*]] = %[[VAL_40]] to %[[VAL_41]] step %[[VAL_39]] unordered iter_args(%[[VAL_44:.*]] = %[[VAL_13]]) -> (!fir.array<10x10x!fir.type<_QFtest_forall_with_ranked_dimensionTt{arr:!fir.array<11xi32>}>>) { -! CHECK: %[[VAL_45:.*]] = fir.call @_QPf(%[[VAL_0]]) : (!fir.ref) -> i32 ! CHECK: %[[VAL_46:.*]] = arith.subi %[[VAL_17]], %[[VAL_17]] : index ! CHECK: %[[VAL_47:.*]] = arith.muli %[[VAL_43]], %[[VAL_23]] : index ! CHECK: %[[VAL_48:.*]] = arith.addi %[[VAL_46]], %[[VAL_47]] : index Index: flang/test/Lower/forall/forall-slice.f90 =================================================================== --- flang/test/Lower/forall/forall-slice.f90 +++ flang/test/Lower/forall/forall-slice.f90 @@ -53,11 +53,11 @@ ! CHECK: %[[VAL_50:.*]] = arith.divsi %[[VAL_49]], %[[VAL_43]] : index ! CHECK: %[[VAL_51:.*]] = arith.cmpi sgt, %[[VAL_50]], %[[VAL_47]] : index ! CHECK: %[[VAL_52:.*]] = arith.select %[[VAL_51]], %[[VAL_50]], %[[VAL_47]] : index +! CHECK: %[[VAL_59:.*]] = fir.call @_QPf(%[[VAL_3]]) : (!fir.ref) -> i32 ! CHECK: %[[VAL_53:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_54:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_55:.*]] = arith.subi %[[VAL_52]], %[[VAL_53]] : index ! CHECK: %[[VAL_56:.*]] = fir.do_loop %[[VAL_57:.*]] = %[[VAL_54]] to %[[VAL_55]] step %[[VAL_53]] unordered iter_args(%[[VAL_58:.*]] = %[[VAL_25]]) -> (!fir.array<10x10x!fir.type<_QFtest_forall_with_sliceTt{arr:!fir.array<11xi32>}>>) { -! CHECK: %[[VAL_59:.*]] = fir.call @_QPf(%[[VAL_3]]) : (!fir.ref) -> i32 ! CHECK: %[[VAL_60:.*]] = arith.subi %[[VAL_40]], %[[VAL_37]] : index ! CHECK: %[[VAL_61:.*]] = arith.muli %[[VAL_57]], %[[VAL_43]] : index ! CHECK: %[[VAL_62:.*]] = arith.addi %[[VAL_60]], %[[VAL_61]] : index Index: flang/test/Lower/forall/test9.f90 =================================================================== --- flang/test/Lower/forall/test9.f90 +++ flang/test/Lower/forall/test9.f90 @@ -16,59 +16,61 @@ end subroutine test9 ! CHECK-LABEL: func @_QPtest9( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref>{{.*}}, %[[VAL_1:.*]]: !fir.ref>{{.*}}, %[[VAL_2:.*]]: !fir.ref{{.*}}) { +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "a"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "b"}, +! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref {fir.bindc_name = "n"}) { ! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"} ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_2]] : !fir.ref ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> i64 -! CHECK: %[[VAL_6A:.*]] = fir.convert %[[VAL_5]] : (i64) -> index -! CHECK: %[[C0:.*]] = arith.constant 0 : index -! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[VAL_6A]], %[[C0]] : index -! CHECK: %[[VAL_6:.*]] = arith.select %[[CMP]], %[[VAL_6A]], %[[C0]] : index -! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_2]] : !fir.ref -! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> i64 -! CHECK: %[[VAL_9A:.*]] = fir.convert %[[VAL_8]] : (i64) -> index -! CHECK: %[[C0_2:.*]] = arith.constant 0 : index -! CHECK: %[[CMP_2:.*]] = arith.cmpi sgt, %[[VAL_9A]], %[[C0_2]] : index -! CHECK: %[[VAL_9:.*]] = arith.select %[[CMP_2]], %[[VAL_9A]], %[[C0_2]] : index -! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i32 -! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i32) -> index -! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_2]] : !fir.ref -! CHECK: %[[VAL_13:.*]] = arith.constant 1 : i32 -! CHECK: %[[VAL_14:.*]] = arith.subi %[[VAL_12]], %[[VAL_13]] : i32 -! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i32) -> index -! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index -! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1> -! CHECK: %[[VAL_18:.*]] = fir.array_load %[[VAL_0]](%[[VAL_17]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array -! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1> -! CHECK: %[[VAL_20:.*]] = fir.array_load %[[VAL_0]](%[[VAL_19]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array -! CHECK: %[[VAL_21:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> -! CHECK: %[[VAL_22:.*]] = fir.array_load %[[VAL_1]](%[[VAL_21]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array -! CHECK: %[[VAL_23:.*]] = fir.do_loop %[[VAL_24:.*]] = %[[VAL_11]] to %[[VAL_15]] step %[[VAL_16]] unordered iter_args(%[[VAL_25:.*]] = %[[VAL_18]]) -> (!fir.array) { -! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_24]] : (index) -> i32 -! CHECK: fir.store %[[VAL_26]] to %[[VAL_3]] : !fir.ref -! CHECK: %[[VAL_27:.*]] = arith.constant 1 : index -! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_3]] : !fir.ref -! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i32) -> i64 -! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i64) -> index -! CHECK: %[[VAL_31:.*]] = arith.subi %[[VAL_30]], %[[VAL_27]] : index -! CHECK: %[[VAL_32:.*]] = arith.constant 1 : index -! CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_3]] : !fir.ref -! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_33]] : (i32) -> i64 -! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_34]] : (i64) -> index -! CHECK: %[[VAL_36:.*]] = arith.subi %[[VAL_35]], %[[VAL_32]] : index -! CHECK: %[[VAL_37:.*]] = fir.array_fetch %[[VAL_20]], %[[VAL_31]] : (!fir.array, index) -> f32 -! CHECK: %[[VAL_38:.*]] = fir.array_fetch %[[VAL_22]], %[[VAL_36]] : (!fir.array, index) -> f32 -! CHECK: %[[VAL_39:.*]] = arith.addf %[[VAL_37]], %[[VAL_38]] : f32 -! CHECK: %[[VAL_40:.*]] = arith.constant 1 : index -! CHECK-DAG: %[[VAL_41:.*]] = fir.load %[[VAL_3]] : !fir.ref -! CHECK-DAG: %[[VAL_42:.*]] = arith.constant 1 : i32 -! CHECK: %[[VAL_43:.*]] = arith.addi %[[VAL_41]], %[[VAL_42]] : i32 -! CHECK: %[[VAL_44:.*]] = fir.convert %[[VAL_43]] : (i32) -> i64 -! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i64) -> index -! CHECK: %[[VAL_46:.*]] = arith.subi %[[VAL_45]], %[[VAL_40]] : index -! CHECK: %[[VAL_47:.*]] = fir.array_update %[[VAL_25]], %[[VAL_39]], %[[VAL_46]] : (!fir.array, f32, index) -> !fir.array -! CHECK: fir.result %[[VAL_47]] : !fir.array +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i64) -> index +! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_8:.*]] = arith.cmpi sgt, %[[VAL_6]], %[[VAL_7]] : index +! CHECK: %[[VAL_9:.*]] = arith.select %[[VAL_8]], %[[VAL_6]], %[[VAL_7]] : index +! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i32) -> i64 +! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index +! CHECK: %[[VAL_13:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_12]], %[[VAL_13]] : index +! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_14]], %[[VAL_12]], %[[VAL_13]] : index +! CHECK: %[[VAL_16:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i32) -> index +! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_2]] : !fir.ref +! CHECK: %[[VAL_19:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_18]], %[[VAL_19]] : i32 +! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> index +! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_23:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_24:.*]] = fir.array_load %[[VAL_0]](%[[VAL_23]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array +! CHECK: %[[VAL_25:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_26:.*]] = fir.array_load %[[VAL_0]](%[[VAL_25]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array +! CHECK: %[[VAL_27:.*]] = fir.shape %[[VAL_15]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_28:.*]] = fir.array_load %[[VAL_1]](%[[VAL_27]]) : (!fir.ref>, !fir.shape<1>) -> !fir.array +! CHECK: %[[VAL_29:.*]] = fir.do_loop %[[VAL_30:.*]] = %[[VAL_17]] to %[[VAL_21]] step %[[VAL_22]] unordered iter_args(%[[VAL_31:.*]] = %[[VAL_24]]) -> (!fir.array) { +! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_30]] : (index) -> i32 +! CHECK: fir.store %[[VAL_32]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_33:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_34]] : (i32) -> i64 +! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i64) -> index +! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_36]], %[[VAL_33]] : index +! CHECK: %[[VAL_38:.*]] = fir.array_fetch %[[VAL_26]], %[[VAL_37]] : (!fir.array, index) -> f32 +! CHECK: %[[VAL_39:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i32) -> i64 +! CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (i64) -> index +! CHECK: %[[VAL_43:.*]] = arith.subi %[[VAL_42]], %[[VAL_39]] : index +! CHECK: %[[VAL_44:.*]] = fir.array_fetch %[[VAL_28]], %[[VAL_43]] : (!fir.array, index) -> f32 +! CHECK: %[[VAL_45:.*]] = arith.addf %[[VAL_38]], %[[VAL_44]] : f32 +! CHECK: %[[VAL_46:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_47:.*]] = fir.load %[[VAL_3]] : !fir.ref +! CHECK: %[[VAL_48:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_49:.*]] = arith.addi %[[VAL_47]], %[[VAL_48]] : i32 +! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i32) -> i64 +! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_50]] : (i64) -> index +! CHECK: %[[VAL_52:.*]] = arith.subi %[[VAL_51]], %[[VAL_46]] : index +! CHECK: %[[VAL_53:.*]] = fir.array_update %[[VAL_31]], %[[VAL_45]], %[[VAL_52]] : (!fir.array, f32, index) -> !fir.array +! CHECK: fir.result %[[VAL_53]] : !fir.array ! CHECK: } -! CHECK: fir.array_merge_store %[[VAL_18]], %[[VAL_48:.*]] to %[[VAL_0]] : !fir.array, !fir.array, !fir.ref> +! CHECK: fir.array_merge_store %[[VAL_24]], %[[VAL_54:.*]] to %[[VAL_0]] : !fir.array, !fir.array, !fir.ref> ! CHECK: return ! CHECK: }