[flang-commits] [flang] 9a7b363 - [flang] Added missing type cast for the implied-do index.
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue May 9 13:26:41 PDT 2023
Author: Slava Zakharin
Date: 2023-05-09T13:26:32-07:00
New Revision: 9a7b363eeb867974aeb511c6ce0cfad723523aed
URL: https://github.com/llvm/llvm-project/commit/9a7b363eeb867974aeb511c6ce0cfad723523aed
DIFF: https://github.com/llvm/llvm-project/commit/9a7b363eeb867974aeb511c6ce0cfad723523aed.diff
LOG: [flang] Added missing type cast for the implied-do index.
The implied-do index value has 'index' type, and it has to be
converted to the original ac-do-variable's data type.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D150150
Added:
flang/test/Lower/HLFIR/array-ctor-index.f90
flang/test/Lower/array-constructor-index.f90
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/ConvertExprToHLFIR.cpp
flang/test/Lower/HLFIR/array-ctor-as-elemental.f90
flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90
flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 7f89fcf88f87d..dead3c54d2430 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -976,7 +976,12 @@ class ScalarExprLowering {
/// Lowering of an <i>ac-do-variable</i>, which is not a Symbol.
ExtValue genval(const Fortran::evaluate::ImpliedDoIndex &var) {
- return converter.impliedDoBinding(toStringRef(var.name));
+ mlir::Value value = converter.impliedDoBinding(toStringRef(var.name));
+ // The index value generated by the implied-do has Index type,
+ // while computations based on it inside the loop body are using
+ // the original data type. So we need to cast it appropriately.
+ mlir::Type varTy = converter.genType(toEvExpr(var));
+ return builder.createConvert(getLoc(), varTy, value);
}
ExtValue genval(const Fortran::evaluate::DescriptorInquiry &desc) {
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 2298e836e4cb7..22425cc441b99 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -1558,7 +1558,13 @@ class HlfirBuilder {
hlfir::EntityWithAttributes
gen(const Fortran::evaluate::ImpliedDoIndex &var) {
mlir::Value value = symMap.lookupImpliedDo(toStringRef(var.name));
- assert(value && "impled do was not mapped");
+ if (!value)
+ fir::emitFatalError(getLoc(), "ac-do-variable has no binding");
+ // The index value generated by the implied-do has Index type,
+ // while computations based on it inside the loop body are using
+ // the original data type. So we need to cast it appropriately.
+ mlir::Type varTy = getConverter().genType(toEvExpr(var));
+ value = getBuilder().createConvert(getLoc(), varTy, value);
return hlfir::EntityWithAttributes{value};
}
diff --git a/flang/test/Lower/HLFIR/array-ctor-as-elemental.f90 b/flang/test/Lower/HLFIR/array-ctor-as-elemental.f90
index 1cd714f38f14b..ff9ecf7ac70ff 100644
--- a/flang/test/Lower/HLFIR/array-ctor-as-elemental.f90
+++ b/flang/test/Lower/HLFIR/array-ctor-as-elemental.f90
@@ -5,65 +5,80 @@ subroutine test_as_simple_elemental(n)
integer :: n
call takes_int([(n+i, i=1,4)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_as_simple_elemental(
-! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}En
-! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
-! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
-! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
-! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
-! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
-! CHECK: ^bb0(%[[VAL_10:.*]]: index):
-! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
-! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
-! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
-! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i32>
-! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_13]] : (index) -> i32
-! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_14]], %[[VAL_15]] : i32
-! CHECK: hlfir.yield_element %[[VAL_16]] : i32
-! CHECK: }
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_9]] : !hlfir.expr<4xi32>
+! CHECK-LABEL: func.func @_QPtest_as_simple_elemental(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_as_simple_elementalEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
+! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
+! CHECK: ^bb0(%[[VAL_10:.*]]: index):
+! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
+! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
+! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
+! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i32>
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_13]] : (index) -> i64
+! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i64) -> i32
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_14]], %[[VAL_16]] : i32
+! CHECK: hlfir.yield_element %[[VAL_17]] : i32
+! CHECK: }
+! CHECK: %[[VAL_18:.*]]:3 = hlfir.associate %[[VAL_19:.*]](%[[VAL_3]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<4xi32>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi32>>, !fir.ref<!fir.array<4xi32>>, i1)
+! CHECK: fir.call @_QPtakes_int(%[[VAL_18]]#1) fastmath<contract> : (!fir.ref<!fir.array<4xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_18]]#1, %[[VAL_18]]#2 : !fir.ref<!fir.array<4xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_19]] : !hlfir.expr<4xi32>
+! CHECK: return
+! CHECK: }
subroutine test_as_strided_elemental(lb, ub, stride)
integer(8) :: lb, ub, stride
call takes_int([(i, i=lb,ub,stride)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_as_strided_elemental(
-! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Elb
-! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Estride
-! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}}Eub
-! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_7]], %[[VAL_8]] : i64
-! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_10]] : i64
-! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_11]], %[[VAL_12]] : i64
-! CHECK: %[[VAL_14:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_13]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_6]], %[[VAL_16]] : i64
-! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
-! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_18]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
-! CHECK: %[[VAL_22:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> index
-! CHECK: %[[VAL_24:.*]] = arith.constant 1 : index
-! CHECK: %[[VAL_25:.*]] = hlfir.elemental %[[VAL_19]] : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
-! CHECK: ^bb0(%[[VAL_26:.*]]: index):
-! CHECK: %[[VAL_27:.*]] = arith.subi %[[VAL_26]], %[[VAL_24]] : index
-! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_27]], %[[VAL_23]] : index
-! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_21]], %[[VAL_28]] : index
-! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (index) -> i32
-! CHECK: hlfir.yield_element %[[VAL_30]] : i32
-! CHECK: }
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_25]] : !hlfir.expr<?xi32>
+! CHECK-LABEL: func.func @_QPtest_as_strided_elemental(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "lb"},
+! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64> {fir.bindc_name = "ub"},
+! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i64> {fir.bindc_name = "stride"}) {
+! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_as_strided_elementalElb"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFtest_as_strided_elementalEstride"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFtest_as_strided_elementalEub"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_7]], %[[VAL_8]] : i64
+! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_10]] : i64
+! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_11]], %[[VAL_12]] : i64
+! CHECK: %[[VAL_14:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_13]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_6]], %[[VAL_16]] : i64
+! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
+! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_18]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
+! CHECK: %[[VAL_22:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> index
+! CHECK: %[[VAL_24:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_25:.*]] = hlfir.elemental %[[VAL_19]] : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
+! CHECK: ^bb0(%[[VAL_26:.*]]: index):
+! CHECK: %[[VAL_27:.*]] = arith.subi %[[VAL_26]], %[[VAL_24]] : index
+! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_27]], %[[VAL_23]] : index
+! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_21]], %[[VAL_28]] : index
+! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (index) -> i64
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (i64) -> i32
+! CHECK: hlfir.yield_element %[[VAL_31]] : i32
+! CHECK: }
+! CHECK: %[[VAL_32:.*]]:3 = hlfir.associate %[[VAL_33:.*]](%[[VAL_19]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
+! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_32]]#1 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<4xi32>>
+! CHECK: fir.call @_QPtakes_int(%[[VAL_34]]) fastmath<contract> : (!fir.ref<!fir.array<4xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_32]]#1, %[[VAL_32]]#2 : !fir.ref<!fir.array<?xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_33]] : !hlfir.expr<?xi32>
+! CHECK: return
+! CHECK: }
subroutine test_as_elemental_with_pure_call(n)
interface
@@ -74,27 +89,32 @@ integer pure function foo(i)
integer :: n
call takes_int([(foo(i), i=1,4)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_as_elemental_with_pure_call(
-! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) {
-! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_as_elemental_with_pure_callEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
-! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
-! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
-! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
-! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
-! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
-! CHECK: ^bb0(%[[VAL_10:.*]]: index):
-! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
-! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
-! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
-! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (index) -> i32
-! CHECK: %[[VAL_15:.*]] = fir.call @_QPfoo(%[[VAL_14]]) fastmath<contract> : (i32) -> i32
-! CHECK: hlfir.yield_element %[[VAL_15]] : i32
-! CHECK: }
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_9]] : !hlfir.expr<4xi32>
+! CHECK-LABEL: func.func @_QPtest_as_elemental_with_pure_call(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_as_elemental_with_pure_callEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
+! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
+! CHECK: ^bb0(%[[VAL_10:.*]]: index):
+! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
+! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
+! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
+! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (index) -> i64
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i64) -> i32
+! CHECK: %[[VAL_16:.*]] = fir.call @_QPfoo(%[[VAL_15]]) fastmath<contract> : (i32) -> i32
+! CHECK: hlfir.yield_element %[[VAL_16]] : i32
+! CHECK: }
+! CHECK: %[[VAL_17:.*]]:3 = hlfir.associate %[[VAL_18:.*]](%[[VAL_3]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<4xi32>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi32>>, !fir.ref<!fir.array<4xi32>>, i1)
+! CHECK: fir.call @_QPtakes_int(%[[VAL_17]]#1) fastmath<contract> : (!fir.ref<!fir.array<4xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_17]]#1, %[[VAL_17]]#2 : !fir.ref<!fir.array<4xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_18]] : !hlfir.expr<4xi32>
+! CHECK: return
+! CHECK: }
! CHECK-LABEL: func.func @_QPtest_with_impure_call(
subroutine test_with_impure_call(n)
diff --git a/flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90 b/flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90
index a3e0d09cfb71a..bd9d9ffcadc41 100644
--- a/flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90
+++ b/flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90
@@ -109,172 +109,197 @@ subroutine test_implied_do(n)
! the implied do contains more than one scalar ac-value.
call takes_int([(42, j, j=1,n)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_implied_do(
-! CHECK: %[[VAL_1:.*]] = fir.alloca index
-! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}En
-! CHECK: %[[VAL_3:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_4:.*]] = arith.constant 2 : i64
-! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_7:.*]] = arith.subi %[[VAL_5]], %[[VAL_6]] : i64
-! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_7]], %[[VAL_8]] : i64
-! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_11:.*]] = arith.divsi %[[VAL_9]], %[[VAL_10]] : i64
-! CHECK: %[[VAL_12:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_13:.*]] = arith.cmpi sgt, %[[VAL_11]], %[[VAL_12]] : i64
-! CHECK: %[[VAL_14:.*]] = arith.select %[[VAL_13]], %[[VAL_11]], %[[VAL_12]] : i64
-! CHECK: %[[VAL_15:.*]] = arith.muli %[[VAL_4]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_3]], %[[VAL_15]] : i64
-! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i64) -> index
-! CHECK: %[[VAL_18:.*]] = arith.constant 1 : index
-! CHECK: fir.store %[[VAL_18]] to %[[VAL_1]] : !fir.ref<index>
-! CHECK: %[[VAL_19:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_17]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
-! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_17]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_21:.*]]:2 = hlfir.declare %[[VAL_19]](%[[VAL_20]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
-! CHECK: %[[VAL_22:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> index
-! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i64) -> index
-! CHECK: %[[VAL_26:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
-! CHECK: fir.do_loop %[[VAL_28:.*]] = %[[VAL_23]] to %[[VAL_25]] step %[[VAL_27]] {
-! CHECK: %[[VAL_29:.*]] = arith.constant 42 : i32
-! CHECK: %[[VAL_30:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
-! CHECK: %[[VAL_31:.*]] = arith.addi %[[VAL_30]], %[[VAL_18]] : index
-! CHECK: fir.store %[[VAL_31]] to %[[VAL_1]] : !fir.ref<index>
-! CHECK: %[[VAL_32:.*]] = hlfir.designate %[[VAL_21]]#0 (%[[VAL_31]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
-! CHECK: hlfir.assign %[[VAL_29]] to %[[VAL_32]] : i32, !fir.ref<i32>
-! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_28]] : (index) -> i32
-! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
-! CHECK: %[[VAL_35:.*]] = arith.addi %[[VAL_34]], %[[VAL_18]] : index
-! CHECK: fir.store %[[VAL_35]] to %[[VAL_1]] : !fir.ref<index>
-! CHECK: %[[VAL_36:.*]] = hlfir.designate %[[VAL_21]]#0 (%[[VAL_35]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
-! CHECK: hlfir.assign %[[VAL_33]] to %[[VAL_36]] : i32, !fir.ref<i32>
-! CHECK: }
-! CHECK: %[[VAL_37:.*]] = arith.constant true
-! CHECK: %[[VAL_38:.*]] = hlfir.as_expr %[[VAL_21]]#0 move %[[VAL_37]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_38]] : !hlfir.expr<?xi32>
+! CHECK-LABEL: func.func @_QPtest_implied_do(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "n"}) {
+! CHECK: %[[VAL_1:.*]] = fir.alloca index
+! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_implied_doEn"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_3:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_4:.*]] = arith.constant 2 : i64
+! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_7:.*]] = arith.subi %[[VAL_5]], %[[VAL_6]] : i64
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_7]], %[[VAL_8]] : i64
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = arith.divsi %[[VAL_9]], %[[VAL_10]] : i64
+! CHECK: %[[VAL_12:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_13:.*]] = arith.cmpi sgt, %[[VAL_11]], %[[VAL_12]] : i64
+! CHECK: %[[VAL_14:.*]] = arith.select %[[VAL_13]], %[[VAL_11]], %[[VAL_12]] : i64
+! CHECK: %[[VAL_15:.*]] = arith.muli %[[VAL_4]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_3]], %[[VAL_15]] : i64
+! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i64) -> index
+! CHECK: %[[VAL_18:.*]] = arith.constant 1 : index
+! CHECK: fir.store %[[VAL_18]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_19:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_17]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
+! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_17]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_21:.*]]:2 = hlfir.declare %[[VAL_19]](%[[VAL_20]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
+! CHECK: %[[VAL_22:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> index
+! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i64) -> index
+! CHECK: %[[VAL_26:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
+! CHECK: fir.do_loop %[[VAL_28:.*]] = %[[VAL_23]] to %[[VAL_25]] step %[[VAL_27]] {
+! CHECK: %[[VAL_29:.*]] = arith.constant 42 : i32
+! CHECK: %[[VAL_30:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_31:.*]] = arith.addi %[[VAL_30]], %[[VAL_18]] : index
+! CHECK: fir.store %[[VAL_31]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_32:.*]] = hlfir.designate %[[VAL_21]]#0 (%[[VAL_31]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
+! CHECK: hlfir.assign %[[VAL_29]] to %[[VAL_32]] : i32, !fir.ref<i32>
+! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_28]] : (index) -> i64
+! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_33]] : (i64) -> i32
+! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_36:.*]] = arith.addi %[[VAL_35]], %[[VAL_18]] : index
+! CHECK: fir.store %[[VAL_36]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_37:.*]] = hlfir.designate %[[VAL_21]]#0 (%[[VAL_36]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
+! CHECK: hlfir.assign %[[VAL_34]] to %[[VAL_37]] : i32, !fir.ref<i32>
+! CHECK: }
+! CHECK: %[[VAL_38:.*]] = arith.constant true
+! CHECK: %[[VAL_39:.*]] = hlfir.as_expr %[[VAL_21]]#0 move %[[VAL_38]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
+! CHECK: %[[VAL_40:.*]]:3 = hlfir.associate %[[VAL_39]](%[[VAL_20]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
+! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]]#1 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<2xi32>>
+! CHECK: fir.call @_QPtakes_int(%[[VAL_41]]) fastmath<contract> : (!fir.ref<!fir.array<2xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_40]]#1, %[[VAL_40]]#2 : !fir.ref<!fir.array<?xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_39]] : !hlfir.expr<?xi32>
+! CHECK: return
+! CHECK: }
subroutine test_strided_implied_do(lb, ub, stride)
integer(8) :: lb, ub, stride
call takes_int([(42, j, j=lb,ub,stride)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_strided_implied_do(
-! CHECK: %[[VAL_3:.*]] = fir.alloca index
-! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Elb
-! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}}Estride
-! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare {{.*}}Eub
-! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_8:.*]] = arith.constant 2 : i64
-! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_9]], %[[VAL_10]] : i64
-! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_11]], %[[VAL_12]] : i64
-! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_15:.*]] = arith.divsi %[[VAL_13]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_17:.*]] = arith.cmpi sgt, %[[VAL_15]], %[[VAL_16]] : i64
-! CHECK: %[[VAL_18:.*]] = arith.select %[[VAL_17]], %[[VAL_15]], %[[VAL_16]] : i64
-! CHECK: %[[VAL_19:.*]] = arith.muli %[[VAL_8]], %[[VAL_18]] : i64
-! CHECK: %[[VAL_20:.*]] = arith.addi %[[VAL_7]], %[[VAL_19]] : i64
-! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
-! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index
-! CHECK: fir.store %[[VAL_22]] to %[[VAL_3]] : !fir.ref<index>
-! CHECK: %[[VAL_23:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_21]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
-! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_21]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_25:.*]]:2 = hlfir.declare %[[VAL_23]](%[[VAL_24]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
-! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
-! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
-! CHECK: %[[VAL_30:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (i64) -> index
-! CHECK: fir.do_loop %[[VAL_32:.*]] = %[[VAL_27]] to %[[VAL_29]] step %[[VAL_31]] {
-! CHECK: %[[VAL_33:.*]] = arith.constant 42 : i32
-! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_3]] : !fir.ref<index>
-! CHECK: %[[VAL_35:.*]] = arith.addi %[[VAL_34]], %[[VAL_22]] : index
-! CHECK: fir.store %[[VAL_35]] to %[[VAL_3]] : !fir.ref<index>
-! CHECK: %[[VAL_36:.*]] = hlfir.designate %[[VAL_25]]#0 (%[[VAL_35]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
-! CHECK: hlfir.assign %[[VAL_33]] to %[[VAL_36]] : i32, !fir.ref<i32>
-! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_32]] : (index) -> i32
-! CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_3]] : !fir.ref<index>
-! CHECK: %[[VAL_39:.*]] = arith.addi %[[VAL_38]], %[[VAL_22]] : index
-! CHECK: fir.store %[[VAL_39]] to %[[VAL_3]] : !fir.ref<index>
-! CHECK: %[[VAL_40:.*]] = hlfir.designate %[[VAL_25]]#0 (%[[VAL_39]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
-! CHECK: hlfir.assign %[[VAL_37]] to %[[VAL_40]] : i32, !fir.ref<i32>
-! CHECK: }
-! CHECK: %[[VAL_41:.*]] = arith.constant true
-! CHECK: %[[VAL_42:.*]] = hlfir.as_expr %[[VAL_25]]#0 move %[[VAL_41]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_42]] : !hlfir.expr<?xi32>
+! CHECK-LABEL: func.func @_QPtest_strided_implied_do(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "lb"},
+! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64> {fir.bindc_name = "ub"},
+! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i64> {fir.bindc_name = "stride"}) {
+! CHECK: %[[VAL_3:.*]] = fir.alloca index
+! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_strided_implied_doElb"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFtest_strided_implied_doEstride"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFtest_strided_implied_doEub"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_8:.*]] = arith.constant 2 : i64
+! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_9]], %[[VAL_10]] : i64
+! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_11]], %[[VAL_12]] : i64
+! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_15:.*]] = arith.divsi %[[VAL_13]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_17:.*]] = arith.cmpi sgt, %[[VAL_15]], %[[VAL_16]] : i64
+! CHECK: %[[VAL_18:.*]] = arith.select %[[VAL_17]], %[[VAL_15]], %[[VAL_16]] : i64
+! CHECK: %[[VAL_19:.*]] = arith.muli %[[VAL_8]], %[[VAL_18]] : i64
+! CHECK: %[[VAL_20:.*]] = arith.addi %[[VAL_7]], %[[VAL_19]] : i64
+! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
+! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index
+! CHECK: fir.store %[[VAL_22]] to %[[VAL_3]] : !fir.ref<index>
+! CHECK: %[[VAL_23:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_21]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
+! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_21]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_25:.*]]:2 = hlfir.declare %[[VAL_23]](%[[VAL_24]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
+! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
+! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
+! CHECK: %[[VAL_30:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (i64) -> index
+! CHECK: fir.do_loop %[[VAL_32:.*]] = %[[VAL_27]] to %[[VAL_29]] step %[[VAL_31]] {
+! CHECK: %[[VAL_33:.*]] = arith.constant 42 : i32
+! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_3]] : !fir.ref<index>
+! CHECK: %[[VAL_35:.*]] = arith.addi %[[VAL_34]], %[[VAL_22]] : index
+! CHECK: fir.store %[[VAL_35]] to %[[VAL_3]] : !fir.ref<index>
+! CHECK: %[[VAL_36:.*]] = hlfir.designate %[[VAL_25]]#0 (%[[VAL_35]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
+! CHECK: hlfir.assign %[[VAL_33]] to %[[VAL_36]] : i32, !fir.ref<i32>
+! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_32]] : (index) -> i64
+! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (i64) -> i32
+! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_3]] : !fir.ref<index>
+! CHECK: %[[VAL_40:.*]] = arith.addi %[[VAL_39]], %[[VAL_22]] : index
+! CHECK: fir.store %[[VAL_40]] to %[[VAL_3]] : !fir.ref<index>
+! CHECK: %[[VAL_41:.*]] = hlfir.designate %[[VAL_25]]#0 (%[[VAL_40]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
+! CHECK: hlfir.assign %[[VAL_38]] to %[[VAL_41]] : i32, !fir.ref<i32>
+! CHECK: }
+! CHECK: %[[VAL_42:.*]] = arith.constant true
+! CHECK: %[[VAL_43:.*]] = hlfir.as_expr %[[VAL_25]]#0 move %[[VAL_42]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
+! CHECK: %[[VAL_44:.*]]:3 = hlfir.associate %[[VAL_43]](%[[VAL_24]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
+! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]]#1 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<2xi32>>
+! CHECK: fir.call @_QPtakes_int(%[[VAL_45]]) fastmath<contract> : (!fir.ref<!fir.array<2xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_44]]#1, %[[VAL_44]]#2 : !fir.ref<!fir.array<?xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_43]] : !hlfir.expr<?xi32>
+! CHECK: return
+! CHECK: }
subroutine test_nested_implied_do(n, m)
integer(8) :: n, m
call takes_int([((i+j, i=1,m), j=1,n)])
end subroutine
-! CHECK-LABEL: func.func @_QPtest_nested_implied_do(
-! CHECK: %[[VAL_2:.*]] = fir.alloca index
-! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Em
-! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}En
-! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_7]], %[[VAL_8]] : i64
-! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_10]] : i64
-! CHECK: %[[VAL_12:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_11]], %[[VAL_12]] : i64
-! CHECK: %[[VAL_14:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_13]], %[[VAL_14]] : i64
-! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_6]], %[[VAL_16]] : i64
-! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_19:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_18]], %[[VAL_19]] : i64
-! CHECK: %[[VAL_21:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_20]], %[[VAL_21]] : i64
-! CHECK: %[[VAL_23:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_24:.*]] = arith.divsi %[[VAL_22]], %[[VAL_23]] : i64
-! CHECK: %[[VAL_25:.*]] = arith.constant 0 : i64
-! CHECK: %[[VAL_26:.*]] = arith.cmpi sgt, %[[VAL_24]], %[[VAL_25]] : i64
-! CHECK: %[[VAL_27:.*]] = arith.select %[[VAL_26]], %[[VAL_24]], %[[VAL_25]] : i64
-! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_17]], %[[VAL_27]] : i64
-! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_5]], %[[VAL_28]] : i64
-! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i64) -> index
-! CHECK: %[[VAL_31:.*]] = arith.constant 1 : index
-! CHECK: fir.store %[[VAL_31]] to %[[VAL_2]] : !fir.ref<index>
-! CHECK: %[[VAL_32:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_30]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
-! CHECK: %[[VAL_33:.*]] = fir.shape %[[VAL_30]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_34:.*]]:2 = hlfir.declare %[[VAL_32]](%[[VAL_33]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
-! CHECK: %[[VAL_35:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i64) -> index
-! CHECK: %[[VAL_37:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (i64) -> index
-! CHECK: %[[VAL_39:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i64) -> index
-! CHECK: fir.do_loop %[[VAL_41:.*]] = %[[VAL_36]] to %[[VAL_38]] step %[[VAL_40]] {
-! CHECK: %[[VAL_42:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (i64) -> index
-! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
-! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i64) -> index
-! CHECK: %[[VAL_46:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_47:.*]] = fir.convert %[[VAL_46]] : (i64) -> index
-! CHECK: fir.do_loop %[[VAL_48:.*]] = %[[VAL_43]] to %[[VAL_45]] step %[[VAL_47]] {
-! CHECK: %[[VAL_49:.*]] = fir.convert %[[VAL_48]] : (index) -> i32
-! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_41]] : (index) -> i32
-! CHECK: %[[VAL_51:.*]] = arith.addi %[[VAL_49]], %[[VAL_50]] : i32
-! CHECK: %[[VAL_52:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
-! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_52]], %[[VAL_31]] : index
-! CHECK: fir.store %[[VAL_53]] to %[[VAL_2]] : !fir.ref<index>
-! CHECK: %[[VAL_54:.*]] = hlfir.designate %[[VAL_34]]#0 (%[[VAL_53]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
-! CHECK: hlfir.assign %[[VAL_51]] to %[[VAL_54]] : i32, !fir.ref<i32>
-! CHECK: }
-! CHECK: }
-! CHECK: %[[VAL_55:.*]] = arith.constant true
-! CHECK: %[[VAL_56:.*]] = hlfir.as_expr %[[VAL_34]]#0 move %[[VAL_55]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
-! CHECK: fir.call
-! CHECK: hlfir.destroy %[[VAL_56]] : !hlfir.expr<?xi32>
+! CHECK-LABEL: func.func @_QPtest_nested_implied_do(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "n"},
+! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64> {fir.bindc_name = "m"}) {
+! CHECK: %[[VAL_2:.*]] = fir.alloca index
+! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFtest_nested_implied_doEm"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_nested_implied_doEn"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_7]], %[[VAL_8]] : i64
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_10]] : i64
+! CHECK: %[[VAL_12:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_11]], %[[VAL_12]] : i64
+! CHECK: %[[VAL_14:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_13]], %[[VAL_14]] : i64
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_6]], %[[VAL_16]] : i64
+! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_19:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_18]], %[[VAL_19]] : i64
+! CHECK: %[[VAL_21:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_20]], %[[VAL_21]] : i64
+! CHECK: %[[VAL_23:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_24:.*]] = arith.divsi %[[VAL_22]], %[[VAL_23]] : i64
+! CHECK: %[[VAL_25:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_26:.*]] = arith.cmpi sgt, %[[VAL_24]], %[[VAL_25]] : i64
+! CHECK: %[[VAL_27:.*]] = arith.select %[[VAL_26]], %[[VAL_24]], %[[VAL_25]] : i64
+! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_17]], %[[VAL_27]] : i64
+! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_5]], %[[VAL_28]] : i64
+! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i64) -> index
+! CHECK: %[[VAL_31:.*]] = arith.constant 1 : index
+! CHECK: fir.store %[[VAL_31]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_32:.*]] = fir.allocmem !fir.array<?xi32>, %[[VAL_30]] {bindc_name = ".tmp.arrayctor", uniq_name = ""}
+! CHECK: %[[VAL_33:.*]] = fir.shape %[[VAL_30]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_34:.*]]:2 = hlfir.declare %[[VAL_32]](%[[VAL_33]]) {uniq_name = ".tmp.arrayctor"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
+! CHECK: %[[VAL_35:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i64) -> index
+! CHECK: %[[VAL_37:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (i64) -> index
+! CHECK: %[[VAL_39:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i64) -> index
+! CHECK: fir.do_loop %[[VAL_41:.*]] = %[[VAL_36]] to %[[VAL_38]] step %[[VAL_40]] {
+! CHECK: %[[VAL_42:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (i64) -> index
+! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i64) -> index
+! CHECK: %[[VAL_46:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_47:.*]] = fir.convert %[[VAL_46]] : (i64) -> index
+! CHECK: fir.do_loop %[[VAL_48:.*]] = %[[VAL_43]] to %[[VAL_45]] step %[[VAL_47]] {
+! CHECK: %[[VAL_49:.*]] = fir.convert %[[VAL_48]] : (index) -> i64
+! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i64) -> i32
+! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_41]] : (index) -> i64
+! CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_51]] : (i64) -> i32
+! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_50]], %[[VAL_52]] : i32
+! CHECK: %[[VAL_54:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_55:.*]] = arith.addi %[[VAL_54]], %[[VAL_31]] : index
+! CHECK: fir.store %[[VAL_55]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_56:.*]] = hlfir.designate %[[VAL_34]]#0 (%[[VAL_55]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
+! CHECK: hlfir.assign %[[VAL_53]] to %[[VAL_56]] : i32, !fir.ref<i32>
+! CHECK: }
+! CHECK: }
+! CHECK: %[[VAL_57:.*]] = arith.constant true
+! CHECK: %[[VAL_58:.*]] = hlfir.as_expr %[[VAL_34]]#0 move %[[VAL_57]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
+! CHECK: %[[VAL_59:.*]]:3 = hlfir.associate %[[VAL_58]](%[[VAL_33]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
+! CHECK: %[[VAL_60:.*]] = fir.convert %[[VAL_59]]#1 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<2xi32>>
+! CHECK: fir.call @_QPtakes_int(%[[VAL_60]]) fastmath<contract> : (!fir.ref<!fir.array<2xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_59]]#1, %[[VAL_59]]#2 : !fir.ref<!fir.array<?xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_58]] : !hlfir.expr<?xi32>
+! CHECK: return
+! CHECK: }
diff --git a/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 b/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90
index 81b29e37a08d8..26b68c3f2cb02 100644
--- a/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90
+++ b/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90
@@ -6,44 +6,58 @@ module arrayctor
subroutine test_loops()
call takes_int([((i, i=1,ifoo()), j=1,ibar())])
end subroutine
-! CHECK-LABEL: func.func @_QMarrayctorPtest_loops() {
-! CHECK: %[[VAL_0:.*]] = fir.alloca i32
-! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<10xi64> {bindc_name = ".rt.arrayctor.vector"}
-! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = ".tmp.arrayctor"}
-! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
-! CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.heap<!fir.array<?xi32>>
-! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
-! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_4]](%[[VAL_5]]) : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
-! CHECK: fir.store %[[VAL_6]] to %[[VAL_2]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
-! CHECK: %[[VAL_7:.*]] = arith.constant false
-! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.array<10xi64>>) -> !fir.llvm_ptr<i8>
-! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<none>>
-! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_8]], %[[VAL_12]], %[[VAL_7]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr<i8>, !fir.ref<!fir.box<none>>, i1, i32, !fir.ref<i8>, i32) -> none
-! CHECK: %[[VAL_15:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i64) -> index
-! CHECK: %[[VAL_17:.*]] = fir.call @_QMarrayctorPibar() {{.*}}: () -> i32
-! 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: fir.do_loop %[[VAL_22:.*]] = %[[VAL_16]] to %[[VAL_19]] step %[[VAL_21]] {
-! CHECK: %[[VAL_23:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_23]] : (i64) -> index
-! CHECK: %[[VAL_25:.*]] = fir.call @_QMarrayctorPifoo() {{.*}}: () -> i32
-! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64
-! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
-! CHECK: %[[VAL_28:.*]] = arith.constant 1 : i64
-! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
-! CHECK: fir.do_loop %[[VAL_30:.*]] = %[[VAL_24]] to %[[VAL_27]] step %[[VAL_29]] {
-! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (index) -> i32
-! CHECK: fir.store %[[VAL_31]] to %[[VAL_0]] : !fir.ref<i32>
-! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<i32>) -> !fir.llvm_ptr<i8>
-! CHECK: %[[VAL_33:.*]] = fir.call @_FortranAPushArrayConstructorSimpleScalar(%[[VAL_8]], %[[VAL_32]]) {{.*}}: (!fir.llvm_ptr<i8>, !fir.llvm_ptr<i8>) -> none
-! CHECK: }
-! CHECK: }
-! CHECK: %[[VAL_34:.*]] = arith.constant true
-! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
-! CHECK: hlfir.as_expr %[[VAL_35]] move %[[VAL_34]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, i1) -> !hlfir.expr<?xi32>
+! CHECK-LABEL: func.func @_QMarrayctorPtest_loops() {
+! CHECK: %[[VAL_0:.*]] = fir.alloca i32
+! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<10xi64> {bindc_name = ".rt.arrayctor.vector"}
+! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = ".tmp.arrayctor"}
+! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.heap<!fir.array<?xi32>>
+! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_4]](%[[VAL_5]]) : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xi32>>>
+! CHECK: fir.store %[[VAL_6]] to %[[VAL_2]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK: %[[VAL_7:.*]] = arith.constant false
+! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.array<10xi64>>) -> !fir.llvm_ptr<i8>
+! CHECK: %[[VAL_9:.*]] = arith.constant 80 : i32
+! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QQcl.{{.*}}) : !fir.ref<!fir.char<1,{{[0-9]*}}>>
+! CHECK: %[[VAL_11:.*]] = arith.constant 7 : i32
+! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_10]] : (!fir.ref<!fir.char<1,{{[0-9]*}}>>) -> !fir.ref<i8>
+! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_8]], %[[VAL_12]], %[[VAL_7]], %[[VAL_9]], %[[VAL_13]], %[[VAL_11]]) fastmath<contract> : (!fir.llvm_ptr<i8>, !fir.ref<!fir.box<none>>, i1, i32, !fir.ref<i8>, i32) -> none
+! CHECK: %[[VAL_15:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i64) -> index
+! CHECK: %[[VAL_17:.*]] = fir.call @_QMarrayctorPibar() fastmath<contract> : () -> i32
+! 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: fir.do_loop %[[VAL_22:.*]] = %[[VAL_16]] to %[[VAL_19]] step %[[VAL_21]] {
+! CHECK: %[[VAL_23:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_23]] : (i64) -> index
+! CHECK: %[[VAL_25:.*]] = fir.call @_QMarrayctorPifoo() fastmath<contract> : () -> i32
+! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64
+! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i64) -> index
+! CHECK: %[[VAL_28:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
+! CHECK: fir.do_loop %[[VAL_30:.*]] = %[[VAL_24]] to %[[VAL_27]] step %[[VAL_29]] {
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_30]] : (index) -> i64
+! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_31]] : (i64) -> i32
+! CHECK: fir.store %[[VAL_32]] to %[[VAL_0]] : !fir.ref<i32>
+! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<i32>) -> !fir.llvm_ptr<i8>
+! CHECK: %[[VAL_34:.*]] = fir.call @_FortranAPushArrayConstructorSimpleScalar(%[[VAL_8]], %[[VAL_33]]) fastmath<contract> : (!fir.llvm_ptr<i8>, !fir.llvm_ptr<i8>) -> none
+! CHECK: }
+! CHECK: }
+! CHECK: %[[VAL_35:.*]] = arith.constant true
+! CHECK: %[[VAL_36:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK: %[[VAL_37:.*]] = hlfir.as_expr %[[VAL_36]] move %[[VAL_35]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, i1) -> !hlfir.expr<?xi32>
+! CHECK: %[[VAL_38:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_39:.*]]:3 = fir.box_dims %[[VAL_36]], %[[VAL_38]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> (index, index, index)
+! CHECK: %[[VAL_40:.*]] = fir.shape %[[VAL_39]]#1 : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_41:.*]]:3 = hlfir.associate %[[VAL_37]](%[[VAL_40]]) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
+! CHECK: fir.call @_QMarrayctorPtakes_int(%[[VAL_41]]#0) fastmath<contract> : (!fir.box<!fir.array<?xi32>>) -> ()
+! CHECK: hlfir.end_associate %[[VAL_41]]#1, %[[VAL_41]]#2 : !fir.ref<!fir.array<?xi32>>, i1
+! CHECK: hlfir.destroy %[[VAL_37]] : !hlfir.expr<?xi32>
+! CHECK: return
+! CHECK: }
subroutine test_arrays(a)
integer :: a(:, :)
diff --git a/flang/test/Lower/HLFIR/array-ctor-index.f90 b/flang/test/Lower/HLFIR/array-ctor-index.f90
new file mode 100644
index 0000000000000..b52a1afb68b2b
--- /dev/null
+++ b/flang/test/Lower/HLFIR/array-ctor-index.f90
@@ -0,0 +1,194 @@
+! Check that the implied-do index value is converted to proper type.
+! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
+
+function test1(k)
+ integer*1 :: k
+ integer*1 :: test1(4)
+ test1 = ([(i*k, integer(8)::i=1,4)])
+end function test1
+! CHECK-LABEL: func.func @_QPtest1(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i8> {fir.bindc_name = "k"}) -> !fir.array<4xi8> {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest1Ek"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.array<4xi8> {bindc_name = "test1", uniq_name = "_QFtest1Etest1"}
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_3]](%[[VAL_4]]) {uniq_name = "_QFtest1Etest1"} : (!fir.ref<!fir.array<4xi8>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi8>>, !fir.ref<!fir.array<4xi8>>)
+! CHECK: %[[VAL_6:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i64) -> index
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_14:.*]]: index):
+! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_12]] : index
+! CHECK: %[[VAL_16:.*]] = arith.muli %[[VAL_15]], %[[VAL_11]] : index
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_9]], %[[VAL_16]] : index
+! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i8>
+! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i8) -> i64
+! CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_18]], %[[VAL_20]] : i64
+! CHECK: hlfir.yield_element %[[VAL_21]] : i64
+! CHECK: }
+! CHECK: %[[VAL_22:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_23:.*]]: index):
+! CHECK: %[[VAL_24:.*]] = hlfir.apply %[[VAL_25:.*]], %[[VAL_23]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_26:.*]] = hlfir.no_reassoc %[[VAL_24]] : i64
+! CHECK: hlfir.yield_element %[[VAL_26]] : i64
+! CHECK: }
+! CHECK: %[[VAL_27:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi8> {
+! CHECK: ^bb0(%[[VAL_28:.*]]: index):
+! CHECK: %[[VAL_29:.*]] = hlfir.apply %[[VAL_30:.*]], %[[VAL_28]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_29]] : (i64) -> i8
+! CHECK: hlfir.yield_element %[[VAL_31]] : i8
+! CHECK: }
+! CHECK: hlfir.assign %[[VAL_32:.*]] to %[[VAL_5]]#0 : !hlfir.expr<4xi8>, !fir.ref<!fir.array<4xi8>>
+! CHECK: hlfir.destroy %[[VAL_32]] : !hlfir.expr<4xi8>
+! CHECK: hlfir.destroy %[[VAL_33:.*]] : !hlfir.expr<4xi64>
+! CHECK: hlfir.destroy %[[VAL_34:.*]] : !hlfir.expr<4xi64>
+! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_5]]#1 : !fir.ref<!fir.array<4xi8>>
+! CHECK: return %[[VAL_35]] : !fir.array<4xi8>
+! CHECK: }
+
+function test2(k)
+ integer*2 :: k
+ integer*2 :: test2(4)
+ test2 = ([(i*k, integer(8)::i=1,4)])
+end function test2
+! CHECK-LABEL: func.func @_QPtest2(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i16> {fir.bindc_name = "k"}) -> !fir.array<4xi16> {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest2Ek"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.array<4xi16> {bindc_name = "test2", uniq_name = "_QFtest2Etest2"}
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_3]](%[[VAL_4]]) {uniq_name = "_QFtest2Etest2"} : (!fir.ref<!fir.array<4xi16>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi16>>, !fir.ref<!fir.array<4xi16>>)
+! CHECK: %[[VAL_6:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i64) -> index
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_14:.*]]: index):
+! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_12]] : index
+! CHECK: %[[VAL_16:.*]] = arith.muli %[[VAL_15]], %[[VAL_11]] : index
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_9]], %[[VAL_16]] : index
+! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i16>
+! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i16) -> i64
+! CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_18]], %[[VAL_20]] : i64
+! CHECK: hlfir.yield_element %[[VAL_21]] : i64
+! CHECK: }
+! CHECK: %[[VAL_22:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_23:.*]]: index):
+! CHECK: %[[VAL_24:.*]] = hlfir.apply %[[VAL_25:.*]], %[[VAL_23]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_26:.*]] = hlfir.no_reassoc %[[VAL_24]] : i64
+! CHECK: hlfir.yield_element %[[VAL_26]] : i64
+! CHECK: }
+! CHECK: %[[VAL_27:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi16> {
+! CHECK: ^bb0(%[[VAL_28:.*]]: index):
+! CHECK: %[[VAL_29:.*]] = hlfir.apply %[[VAL_30:.*]], %[[VAL_28]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_29]] : (i64) -> i16
+! CHECK: hlfir.yield_element %[[VAL_31]] : i16
+! CHECK: }
+! CHECK: hlfir.assign %[[VAL_32:.*]] to %[[VAL_5]]#0 : !hlfir.expr<4xi16>, !fir.ref<!fir.array<4xi16>>
+! CHECK: hlfir.destroy %[[VAL_32]] : !hlfir.expr<4xi16>
+! CHECK: hlfir.destroy %[[VAL_33:.*]] : !hlfir.expr<4xi64>
+! CHECK: hlfir.destroy %[[VAL_34:.*]] : !hlfir.expr<4xi64>
+! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_5]]#1 : !fir.ref<!fir.array<4xi16>>
+! CHECK: return %[[VAL_35]] : !fir.array<4xi16>
+! CHECK: }
+
+function test3(k)
+ integer*4 :: k
+ integer*4 :: test3(4)
+ test3 = ([(i*k, integer(8)::i=1,4)])
+end function test3
+! CHECK-LABEL: func.func @_QPtest3(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "k"}) -> !fir.array<4xi32> {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest3Ek"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.array<4xi32> {bindc_name = "test3", uniq_name = "_QFtest3Etest3"}
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_3]](%[[VAL_4]]) {uniq_name = "_QFtest3Etest3"} : (!fir.ref<!fir.array<4xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi32>>, !fir.ref<!fir.array<4xi32>>)
+! CHECK: %[[VAL_6:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i64) -> index
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_14:.*]]: index):
+! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_12]] : index
+! CHECK: %[[VAL_16:.*]] = arith.muli %[[VAL_15]], %[[VAL_11]] : index
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_9]], %[[VAL_16]] : index
+! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i32>
+! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i32) -> i64
+! CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_18]], %[[VAL_20]] : i64
+! CHECK: hlfir.yield_element %[[VAL_21]] : i64
+! CHECK: }
+! CHECK: %[[VAL_22:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_23:.*]]: index):
+! CHECK: %[[VAL_24:.*]] = hlfir.apply %[[VAL_25:.*]], %[[VAL_23]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_26:.*]] = hlfir.no_reassoc %[[VAL_24]] : i64
+! CHECK: hlfir.yield_element %[[VAL_26]] : i64
+! CHECK: }
+! CHECK: %[[VAL_27:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
+! CHECK: ^bb0(%[[VAL_28:.*]]: index):
+! CHECK: %[[VAL_29:.*]] = hlfir.apply %[[VAL_30:.*]], %[[VAL_28]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_29]] : (i64) -> i32
+! CHECK: hlfir.yield_element %[[VAL_31]] : i32
+! CHECK: }
+! CHECK: hlfir.assign %[[VAL_32:.*]] to %[[VAL_5]]#0 : !hlfir.expr<4xi32>, !fir.ref<!fir.array<4xi32>>
+! CHECK: hlfir.destroy %[[VAL_32]] : !hlfir.expr<4xi32>
+! CHECK: hlfir.destroy %[[VAL_33:.*]] : !hlfir.expr<4xi64>
+! CHECK: hlfir.destroy %[[VAL_34:.*]] : !hlfir.expr<4xi64>
+! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_5]]#1 : !fir.ref<!fir.array<4xi32>>
+! CHECK: return %[[VAL_35]] : !fir.array<4xi32>
+! CHECK: }
+
+function test4(k)
+ integer*8 :: k
+ integer*8 :: test4(4)
+ test4 = ([(i*k, integer(8)::i=1,4)])
+end function test4
+! CHECK-LABEL: func.func @_QPtest4(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "k"}) -> !fir.array<4xi64> {
+! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest4Ek"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
+! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.array<4xi64> {bindc_name = "test4", uniq_name = "_QFtest4Etest4"}
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_3]](%[[VAL_4]]) {uniq_name = "_QFtest4Etest4"} : (!fir.ref<!fir.array<4xi64>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi64>>, !fir.ref<!fir.array<4xi64>>)
+! CHECK: %[[VAL_6:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i64) -> index
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_14:.*]]: index):
+! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_12]] : index
+! CHECK: %[[VAL_16:.*]] = arith.muli %[[VAL_15]], %[[VAL_11]] : index
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_9]], %[[VAL_16]] : index
+! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i64>
+! CHECK: %[[VAL_20:.*]] = arith.muli %[[VAL_18]], %[[VAL_19]] : i64
+! CHECK: hlfir.yield_element %[[VAL_20]] : i64
+! CHECK: }
+! CHECK: %[[VAL_21:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<4xi64> {
+! CHECK: ^bb0(%[[VAL_22:.*]]: index):
+! CHECK: %[[VAL_23:.*]] = hlfir.apply %[[VAL_24:.*]], %[[VAL_22]] : (!hlfir.expr<4xi64>, index) -> i64
+! CHECK: %[[VAL_25:.*]] = hlfir.no_reassoc %[[VAL_23]] : i64
+! CHECK: hlfir.yield_element %[[VAL_25]] : i64
+! CHECK: }
+! CHECK: hlfir.assign %[[VAL_26:.*]] to %[[VAL_5]]#0 : !hlfir.expr<4xi64>, !fir.ref<!fir.array<4xi64>>
+! CHECK: hlfir.destroy %[[VAL_26]] : !hlfir.expr<4xi64>
+! CHECK: hlfir.destroy %[[VAL_27:.*]] : !hlfir.expr<4xi64>
+! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_5]]#1 : !fir.ref<!fir.array<4xi64>>
+! CHECK: return %[[VAL_28]] : !fir.array<4xi64>
+! CHECK: }
diff --git a/flang/test/Lower/array-constructor-index.f90 b/flang/test/Lower/array-constructor-index.f90
new file mode 100644
index 0000000000000..8332fc5f72091
--- /dev/null
+++ b/flang/test/Lower/array-constructor-index.f90
@@ -0,0 +1,300 @@
+! Check that the implied-do index value is converted to proper type.
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+function test1(k)
+ integer*1 :: k
+ integer*1 :: test1(4)
+ test1 = ([(i*k, integer(8)::i=1,4)])
+end function test1
+! CHECK-LABEL: func.func @_QPtest1(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i8> {fir.bindc_name = "k"}) -> !fir.array<4xi8> {
+! CHECK: %[[VAL_1:.*]] = fir.alloca index {bindc_name = ".buff.pos"}
+! CHECK: %[[VAL_2:.*]] = fir.alloca index {bindc_name = ".buff.size"}
+! CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.array<4xi8> {bindc_name = "test1", uniq_name = "_QFtest1Etest1"}
+! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_6:.*]] = fir.array_load %[[VAL_4]](%[[VAL_5]]) : (!fir.ref<!fir.array<4xi8>>, !fir.shape<1>) -> !fir.array<4xi8>
+! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
+! CHECK: fir.store %[[VAL_7]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_8:.*]] = fir.allocmem !fir.array<4xi64>
+! CHECK: %[[VAL_9:.*]] = arith.constant 4 : index
+! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 4 : i64
+! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i64) -> index
+! CHECK: %[[VAL_14:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i64) -> index
+! CHECK: %[[VAL_16:.*]] = fir.do_loop %[[VAL_17:.*]] = %[[VAL_11]] to %[[VAL_13]] step %[[VAL_15]] iter_args(%[[VAL_18:.*]] = %[[VAL_8]]) -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_0]] : !fir.ref<i8>
+! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i8) -> i64
+! CHECK: %[[VAL_22:.*]] = arith.muli %[[VAL_19]], %[[VAL_21]] : i64
+! CHECK: %[[VAL_23:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_24:.*]] = fir.zero_bits !fir.ref<!fir.array<4xi64>>
+! CHECK: %[[VAL_25:.*]] = fir.coordinate_of %[[VAL_24]], %[[VAL_23]] : (!fir.ref<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (!fir.ref<i64>) -> index
+! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_29:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_27]], %[[VAL_29]] : index
+! CHECK: %[[VAL_31:.*]] = arith.cmpi sle, %[[VAL_28]], %[[VAL_30]] : index
+! CHECK: %[[VAL_32:.*]] = fir.if %[[VAL_31]] -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_33:.*]] = arith.constant 2 : index
+! CHECK: %[[VAL_34:.*]] = arith.muli %[[VAL_30]], %[[VAL_33]] : index
+! CHECK: fir.store %[[VAL_34]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_35:.*]] = arith.muli %[[VAL_34]], %[[VAL_26]] : index
+! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_18]] : (!fir.heap<!fir.array<4xi64>>) -> !fir.ref<i8>
+! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_35]] : (index) -> i64
+! CHECK: %[[VAL_38:.*]] = fir.call @realloc(%[[VAL_36]], %[[VAL_37]]) fastmath<contract> : (!fir.ref<i8>, i64) -> !fir.ref<i8>
+! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (!fir.ref<i8>) -> !fir.heap<!fir.array<4xi64>>
+! CHECK: fir.result %[[VAL_39]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: } else {
+! CHECK: fir.result %[[VAL_18]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_40:.*]] = fir.coordinate_of %[[VAL_41:.*]], %[[VAL_27]] : (!fir.heap<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: fir.store %[[VAL_22]] to %[[VAL_40]] : !fir.ref<i64>
+! CHECK: fir.store %[[VAL_30]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: fir.result %[[VAL_41]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_43:.*]] = fir.shape %[[VAL_42]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_44:.*]] = fir.array_load %[[VAL_45:.*]](%[[VAL_43]]) : (!fir.heap<!fir.array<4xi64>>, !fir.shape<1>) -> !fir.array<4xi64>
+! CHECK: %[[VAL_46:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_47:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_48:.*]] = arith.subi %[[VAL_3]], %[[VAL_46]] : index
+! CHECK: %[[VAL_49:.*]] = fir.do_loop %[[VAL_50:.*]] = %[[VAL_47]] to %[[VAL_48]] step %[[VAL_46]] unordered iter_args(%[[VAL_51:.*]] = %[[VAL_6]]) -> (!fir.array<4xi8>) {
+! CHECK: %[[VAL_52:.*]] = fir.array_fetch %[[VAL_44]], %[[VAL_50]] : (!fir.array<4xi64>, index) -> i64
+! CHECK: %[[VAL_53:.*]] = fir.no_reassoc %[[VAL_52]] : i64
+! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i64) -> i8
+! CHECK: %[[VAL_55:.*]] = fir.array_update %[[VAL_51]], %[[VAL_54]], %[[VAL_50]] : (!fir.array<4xi8>, i8, index) -> !fir.array<4xi8>
+! CHECK: fir.result %[[VAL_55]] : !fir.array<4xi8>
+! CHECK: }
+! CHECK: fir.array_merge_store %[[VAL_6]], %[[VAL_56:.*]] to %[[VAL_4]] : !fir.array<4xi8>, !fir.array<4xi8>, !fir.ref<!fir.array<4xi8>>
+! CHECK: fir.freemem %[[VAL_45]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: %[[VAL_57:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.array<4xi8>>
+! CHECK: return %[[VAL_57]] : !fir.array<4xi8>
+! CHECK: }
+
+function test2(k)
+ integer*2 :: k
+ integer*2 :: test2(4)
+ test2 = ([(i*k, integer(8)::i=1,4)])
+end function test2
+! CHECK-LABEL: func.func @_QPtest2(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i16> {fir.bindc_name = "k"}) -> !fir.array<4xi16> {
+! CHECK: %[[VAL_1:.*]] = fir.alloca index {bindc_name = ".buff.pos"}
+! CHECK: %[[VAL_2:.*]] = fir.alloca index {bindc_name = ".buff.size"}
+! CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.array<4xi16> {bindc_name = "test2", uniq_name = "_QFtest2Etest2"}
+! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_6:.*]] = fir.array_load %[[VAL_4]](%[[VAL_5]]) : (!fir.ref<!fir.array<4xi16>>, !fir.shape<1>) -> !fir.array<4xi16>
+! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
+! CHECK: fir.store %[[VAL_7]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_8:.*]] = fir.allocmem !fir.array<4xi64>
+! CHECK: %[[VAL_9:.*]] = arith.constant 4 : index
+! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 4 : i64
+! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i64) -> index
+! CHECK: %[[VAL_14:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i64) -> index
+! CHECK: %[[VAL_16:.*]] = fir.do_loop %[[VAL_17:.*]] = %[[VAL_11]] to %[[VAL_13]] step %[[VAL_15]] iter_args(%[[VAL_18:.*]] = %[[VAL_8]]) -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_0]] : !fir.ref<i16>
+! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i16) -> i64
+! CHECK: %[[VAL_22:.*]] = arith.muli %[[VAL_19]], %[[VAL_21]] : i64
+! CHECK: %[[VAL_23:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_24:.*]] = fir.zero_bits !fir.ref<!fir.array<4xi64>>
+! CHECK: %[[VAL_25:.*]] = fir.coordinate_of %[[VAL_24]], %[[VAL_23]] : (!fir.ref<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (!fir.ref<i64>) -> index
+! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_29:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_27]], %[[VAL_29]] : index
+! CHECK: %[[VAL_31:.*]] = arith.cmpi sle, %[[VAL_28]], %[[VAL_30]] : index
+! CHECK: %[[VAL_32:.*]] = fir.if %[[VAL_31]] -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_33:.*]] = arith.constant 2 : index
+! CHECK: %[[VAL_34:.*]] = arith.muli %[[VAL_30]], %[[VAL_33]] : index
+! CHECK: fir.store %[[VAL_34]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_35:.*]] = arith.muli %[[VAL_34]], %[[VAL_26]] : index
+! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_18]] : (!fir.heap<!fir.array<4xi64>>) -> !fir.ref<i8>
+! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_35]] : (index) -> i64
+! CHECK: %[[VAL_38:.*]] = fir.call @realloc(%[[VAL_36]], %[[VAL_37]]) fastmath<contract> : (!fir.ref<i8>, i64) -> !fir.ref<i8>
+! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (!fir.ref<i8>) -> !fir.heap<!fir.array<4xi64>>
+! CHECK: fir.result %[[VAL_39]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: } else {
+! CHECK: fir.result %[[VAL_18]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_40:.*]] = fir.coordinate_of %[[VAL_41:.*]], %[[VAL_27]] : (!fir.heap<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: fir.store %[[VAL_22]] to %[[VAL_40]] : !fir.ref<i64>
+! CHECK: fir.store %[[VAL_30]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: fir.result %[[VAL_41]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_43:.*]] = fir.shape %[[VAL_42]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_44:.*]] = fir.array_load %[[VAL_45:.*]](%[[VAL_43]]) : (!fir.heap<!fir.array<4xi64>>, !fir.shape<1>) -> !fir.array<4xi64>
+! CHECK: %[[VAL_46:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_47:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_48:.*]] = arith.subi %[[VAL_3]], %[[VAL_46]] : index
+! CHECK: %[[VAL_49:.*]] = fir.do_loop %[[VAL_50:.*]] = %[[VAL_47]] to %[[VAL_48]] step %[[VAL_46]] unordered iter_args(%[[VAL_51:.*]] = %[[VAL_6]]) -> (!fir.array<4xi16>) {
+! CHECK: %[[VAL_52:.*]] = fir.array_fetch %[[VAL_44]], %[[VAL_50]] : (!fir.array<4xi64>, index) -> i64
+! CHECK: %[[VAL_53:.*]] = fir.no_reassoc %[[VAL_52]] : i64
+! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i64) -> i16
+! CHECK: %[[VAL_55:.*]] = fir.array_update %[[VAL_51]], %[[VAL_54]], %[[VAL_50]] : (!fir.array<4xi16>, i16, index) -> !fir.array<4xi16>
+! CHECK: fir.result %[[VAL_55]] : !fir.array<4xi16>
+! CHECK: }
+! CHECK: fir.array_merge_store %[[VAL_6]], %[[VAL_56:.*]] to %[[VAL_4]] : !fir.array<4xi16>, !fir.array<4xi16>, !fir.ref<!fir.array<4xi16>>
+! CHECK: fir.freemem %[[VAL_45]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: %[[VAL_57:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.array<4xi16>>
+! CHECK: return %[[VAL_57]] : !fir.array<4xi16>
+! CHECK: }
+
+function test3(k)
+ integer*4 :: k
+ integer*4 :: test3(4)
+ test3 = ([(i*k, integer(8)::i=1,4)])
+end function test3
+! CHECK-LABEL: func.func @_QPtest3(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "k"}) -> !fir.array<4xi32> {
+! CHECK: %[[VAL_1:.*]] = fir.alloca index {bindc_name = ".buff.pos"}
+! CHECK: %[[VAL_2:.*]] = fir.alloca index {bindc_name = ".buff.size"}
+! CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.array<4xi32> {bindc_name = "test3", uniq_name = "_QFtest3Etest3"}
+! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_6:.*]] = fir.array_load %[[VAL_4]](%[[VAL_5]]) : (!fir.ref<!fir.array<4xi32>>, !fir.shape<1>) -> !fir.array<4xi32>
+! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
+! CHECK: fir.store %[[VAL_7]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_8:.*]] = fir.allocmem !fir.array<4xi64>
+! CHECK: %[[VAL_9:.*]] = arith.constant 4 : index
+! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 4 : i64
+! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i64) -> index
+! CHECK: %[[VAL_14:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i64) -> index
+! CHECK: %[[VAL_16:.*]] = fir.do_loop %[[VAL_17:.*]] = %[[VAL_11]] to %[[VAL_13]] step %[[VAL_15]] iter_args(%[[VAL_18:.*]] = %[[VAL_8]]) -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
+! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> i64
+! CHECK: %[[VAL_22:.*]] = arith.muli %[[VAL_19]], %[[VAL_21]] : i64
+! CHECK: %[[VAL_23:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_24:.*]] = fir.zero_bits !fir.ref<!fir.array<4xi64>>
+! CHECK: %[[VAL_25:.*]] = fir.coordinate_of %[[VAL_24]], %[[VAL_23]] : (!fir.ref<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (!fir.ref<i64>) -> index
+! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_29:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_27]], %[[VAL_29]] : index
+! CHECK: %[[VAL_31:.*]] = arith.cmpi sle, %[[VAL_28]], %[[VAL_30]] : index
+! CHECK: %[[VAL_32:.*]] = fir.if %[[VAL_31]] -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_33:.*]] = arith.constant 2 : index
+! CHECK: %[[VAL_34:.*]] = arith.muli %[[VAL_30]], %[[VAL_33]] : index
+! CHECK: fir.store %[[VAL_34]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_35:.*]] = arith.muli %[[VAL_34]], %[[VAL_26]] : index
+! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_18]] : (!fir.heap<!fir.array<4xi64>>) -> !fir.ref<i8>
+! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_35]] : (index) -> i64
+! CHECK: %[[VAL_38:.*]] = fir.call @realloc(%[[VAL_36]], %[[VAL_37]]) fastmath<contract> : (!fir.ref<i8>, i64) -> !fir.ref<i8>
+! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (!fir.ref<i8>) -> !fir.heap<!fir.array<4xi64>>
+! CHECK: fir.result %[[VAL_39]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: } else {
+! CHECK: fir.result %[[VAL_18]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_40:.*]] = fir.coordinate_of %[[VAL_41:.*]], %[[VAL_27]] : (!fir.heap<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: fir.store %[[VAL_22]] to %[[VAL_40]] : !fir.ref<i64>
+! CHECK: fir.store %[[VAL_30]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: fir.result %[[VAL_41]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_43:.*]] = fir.shape %[[VAL_42]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_44:.*]] = fir.array_load %[[VAL_45:.*]](%[[VAL_43]]) : (!fir.heap<!fir.array<4xi64>>, !fir.shape<1>) -> !fir.array<4xi64>
+! CHECK: %[[VAL_46:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_47:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_48:.*]] = arith.subi %[[VAL_3]], %[[VAL_46]] : index
+! CHECK: %[[VAL_49:.*]] = fir.do_loop %[[VAL_50:.*]] = %[[VAL_47]] to %[[VAL_48]] step %[[VAL_46]] unordered iter_args(%[[VAL_51:.*]] = %[[VAL_6]]) -> (!fir.array<4xi32>) {
+! CHECK: %[[VAL_52:.*]] = fir.array_fetch %[[VAL_44]], %[[VAL_50]] : (!fir.array<4xi64>, index) -> i64
+! CHECK: %[[VAL_53:.*]] = fir.no_reassoc %[[VAL_52]] : i64
+! CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i64) -> i32
+! CHECK: %[[VAL_55:.*]] = fir.array_update %[[VAL_51]], %[[VAL_54]], %[[VAL_50]] : (!fir.array<4xi32>, i32, index) -> !fir.array<4xi32>
+! CHECK: fir.result %[[VAL_55]] : !fir.array<4xi32>
+! CHECK: }
+! CHECK: fir.array_merge_store %[[VAL_6]], %[[VAL_56:.*]] to %[[VAL_4]] : !fir.array<4xi32>, !fir.array<4xi32>, !fir.ref<!fir.array<4xi32>>
+! CHECK: fir.freemem %[[VAL_45]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: %[[VAL_57:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.array<4xi32>>
+! CHECK: return %[[VAL_57]] : !fir.array<4xi32>
+! CHECK: }
+
+function test4(k)
+ integer*8 :: k
+ integer*8 :: test4(4)
+ test4 = ([(i*k, integer(8)::i=1,4)])
+end function test4
+! CHECK-LABEL: func.func @_QPtest4(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i64> {fir.bindc_name = "k"}) -> !fir.array<4xi64> {
+! CHECK: %[[VAL_1:.*]] = fir.alloca index {bindc_name = ".buff.pos"}
+! CHECK: %[[VAL_2:.*]] = fir.alloca index {bindc_name = ".buff.size"}
+! CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
+! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.array<4xi64> {bindc_name = "test4", uniq_name = "_QFtest4Etest4"}
+! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_6:.*]] = fir.array_load %[[VAL_4]](%[[VAL_5]]) : (!fir.ref<!fir.array<4xi64>>, !fir.shape<1>) -> !fir.array<4xi64>
+! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
+! CHECK: fir.store %[[VAL_7]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_8:.*]] = fir.allocmem !fir.array<4xi64>
+! CHECK: %[[VAL_9:.*]] = arith.constant 4 : index
+! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index
+! CHECK: %[[VAL_12:.*]] = arith.constant 4 : i64
+! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i64) -> index
+! CHECK: %[[VAL_14:.*]] = arith.constant 1 : i64
+! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i64) -> index
+! CHECK: %[[VAL_16:.*]] = fir.do_loop %[[VAL_17:.*]] = %[[VAL_11]] to %[[VAL_13]] step %[[VAL_15]] iter_args(%[[VAL_18:.*]] = %[[VAL_8]]) -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_17]] : (index) -> i64
+! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_0]] : !fir.ref<i64>
+! CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_19]], %[[VAL_20]] : i64
+! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_23:.*]] = fir.zero_bits !fir.ref<!fir.array<4xi64>>
+! CHECK: %[[VAL_24:.*]] = fir.coordinate_of %[[VAL_23]], %[[VAL_22]] : (!fir.ref<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (!fir.ref<i64>) -> index
+! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_28:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_26]], %[[VAL_28]] : index
+! CHECK: %[[VAL_30:.*]] = arith.cmpi sle, %[[VAL_27]], %[[VAL_29]] : index
+! CHECK: %[[VAL_31:.*]] = fir.if %[[VAL_30]] -> (!fir.heap<!fir.array<4xi64>>) {
+! CHECK: %[[VAL_32:.*]] = arith.constant 2 : index
+! CHECK: %[[VAL_33:.*]] = arith.muli %[[VAL_29]], %[[VAL_32]] : index
+! CHECK: fir.store %[[VAL_33]] to %[[VAL_2]] : !fir.ref<index>
+! CHECK: %[[VAL_34:.*]] = arith.muli %[[VAL_33]], %[[VAL_25]] : index
+! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_18]] : (!fir.heap<!fir.array<4xi64>>) -> !fir.ref<i8>
+! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_34]] : (index) -> i64
+! CHECK: %[[VAL_37:.*]] = fir.call @realloc(%[[VAL_35]], %[[VAL_36]]) fastmath<contract> : (!fir.ref<i8>, i64) -> !fir.ref<i8>
+! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (!fir.ref<i8>) -> !fir.heap<!fir.array<4xi64>>
+! CHECK: fir.result %[[VAL_38]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: } else {
+! CHECK: fir.result %[[VAL_18]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_39:.*]] = fir.coordinate_of %[[VAL_40:.*]], %[[VAL_26]] : (!fir.heap<!fir.array<4xi64>>, index) -> !fir.ref<i64>
+! CHECK: fir.store %[[VAL_21]] to %[[VAL_39]] : !fir.ref<i64>
+! CHECK: fir.store %[[VAL_29]] to %[[VAL_1]] : !fir.ref<index>
+! CHECK: fir.result %[[VAL_40]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: }
+! CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_1]] : !fir.ref<index>
+! CHECK: %[[VAL_42:.*]] = fir.shape %[[VAL_41]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_43:.*]] = fir.array_load %[[VAL_44:.*]](%[[VAL_42]]) : (!fir.heap<!fir.array<4xi64>>, !fir.shape<1>) -> !fir.array<4xi64>
+! CHECK: %[[VAL_45:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_46:.*]] = arith.constant 0 : index
+! CHECK: %[[VAL_47:.*]] = arith.subi %[[VAL_3]], %[[VAL_45]] : index
+! CHECK: %[[VAL_48:.*]] = fir.do_loop %[[VAL_49:.*]] = %[[VAL_46]] to %[[VAL_47]] step %[[VAL_45]] unordered iter_args(%[[VAL_50:.*]] = %[[VAL_6]]) -> (!fir.array<4xi64>) {
+! CHECK: %[[VAL_51:.*]] = fir.array_fetch %[[VAL_43]], %[[VAL_49]] : (!fir.array<4xi64>, index) -> i64
+! CHECK: %[[VAL_52:.*]] = fir.no_reassoc %[[VAL_51]] : i64
+! CHECK: %[[VAL_53:.*]] = fir.array_update %[[VAL_50]], %[[VAL_52]], %[[VAL_49]] : (!fir.array<4xi64>, i64, index) -> !fir.array<4xi64>
+! CHECK: fir.result %[[VAL_53]] : !fir.array<4xi64>
+! CHECK: }
+! CHECK: fir.array_merge_store %[[VAL_6]], %[[VAL_54:.*]] to %[[VAL_4]] : !fir.array<4xi64>, !fir.array<4xi64>, !fir.ref<!fir.array<4xi64>>
+! CHECK: fir.freemem %[[VAL_44]] : !fir.heap<!fir.array<4xi64>>
+! CHECK: %[[VAL_55:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.array<4xi64>>
+! CHECK: return %[[VAL_55]] : !fir.array<4xi64>
+! CHECK: }
More information about the flang-commits
mailing list