diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -543,6 +543,10 @@ /// Unwrap integer constant from an mlir::Value. llvm::Optional getIntIfConstant(mlir::Value value); +/// Get the integer constants of triplet and compute the extent. +llvm::Optional +getExtentFromTriplet(mlir::Value lb, mlir::Value ub, mlir::Value stride); + /// Generate max(\p value, 0) where \p value is a scalar integer. mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value value); diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -6090,9 +6090,14 @@ mlir::Operation::operand_range triples = slOp.getTriples(); fir::SequenceType::Shape shape; // reduce the rank for each invariant dimension - for (unsigned i = 1, end = triples.size(); i < end; i += 3) - if (!mlir::isa_and_nonnull(triples[i].getDefiningOp())) + for (unsigned i = 1, end = triples.size(); i < end; i += 3) { + if (auto extent = fir::factory::getExtentFromTriplet( + triples[i - 1], triples[i], triples[i + 1])) + shape.push_back(*extent); + else if (!mlir::isa_and_nonnull( + triples[i].getDefiningOp())) shape.push_back(fir::SequenceType::getUnknownExtent()); + } return fir::SequenceType::get(shape, seqTy.getEleTy()); } // not sliced, so no change in rank diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -1227,6 +1227,32 @@ return {}; } +llvm::Optional +fir::factory::getExtentFromTriplet(mlir::Value lb, mlir::Value ub, + mlir::Value stride) { + std::function(mlir::Value)> getConstantValue = + [&](mlir::Value value) -> llvm::Optional { + if (auto valInt = fir::factory::getIntIfConstant(value)) + return valInt; + else if (auto valOp = mlir::dyn_cast(value.getDefiningOp())) + return getConstantValue(valOp.getValue()); + return {}; + }; + if (auto lbInt = getConstantValue(lb)) { + if (auto ubInt = getConstantValue(ub)) { + if (auto strideInt = getConstantValue(stride)) { + if (strideInt.value() != 0) { + std::int64_t extent = + 1 + (ubInt.value() - lbInt.value()) / strideInt.value(); + if (extent > 0) + return extent; + } + } + } + } + return {}; +} + mlir::Value fir::factory::genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value value) { diff --git a/flang/test/Lower/Intrinsics/reshape.f90 b/flang/test/Lower/Intrinsics/reshape.f90 --- a/flang/test/Lower/Intrinsics/reshape.f90 +++ b/flang/test/Lower/Intrinsics/reshape.f90 @@ -54,3 +54,29 @@ ! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_28]] : (!fir.box>>) -> !fir.box ! CHECK: %[[VAL_41:.*]] = fir.call @_FortranAReshape({{.*}}, {{.*}}, %{{.*}}, %[[VAL_38]], %[[VAL_39]], %{{.*}}, %{{.*}}) : (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> none end subroutine + +! CHECK-LABEL: func.func @_QPtest_reshape_shape_slice() { +! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QFtest_reshape_shape_sliceEdims) : !fir.ref> +! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index +! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QFtest_reshape_shape_sliceEtmp) : !fir.ref> +! CHECK: %[[VAL_4:.*]] = arith.constant 4 : index +! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_3]](%[[VAL_5]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> +! CHECK: %[[VAL_7:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index +! CHECK: %[[VAL_9:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i64) -> index +! CHECK: %[[VAL_11:.*]] = arith.constant 2 : i64 +! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index +! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_14:.*]] = fir.slice %[[VAL_8]], %[[VAL_12]], %[[VAL_10]] : (index, index, index) -> !fir.slice<1> +! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_1]](%[[VAL_13]]) [%[[VAL_14]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_6]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_15]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_30:.*]] = fir.call @_FortranAReshape(%{{.*}}, %[[VAL_25]], %[[VAL_26]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> none +subroutine test_reshape_shape_slice() + integer, parameter :: i = 1 + real :: tmp(4) = [1,2,3,4] + integer :: dims(4) = [2,2,2,2] + call some_proc(reshape(tmp, dims(i:2))) +end diff --git a/flang/test/Lower/Intrinsics/size.f90 b/flang/test/Lower/Intrinsics/size.f90 --- a/flang/test/Lower/Intrinsics/size.f90 +++ b/flang/test/Lower/Intrinsics/size.f90 @@ -27,17 +27,17 @@ ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_c1_i64_1]] : (i64) -> index ! CHECK: %[[VAL_9:.*]] = fir.shape_shift %[[VAL_c1]], %[[VAL_c10]], %[[VAL_cneg10]], %[[VAL_c21]] : (index, index, index, index) -> !fir.shapeshift<2> ! CHECK: %[[VAL_10:.*]] = fir.slice %[[VAL_3]], %[[VAL_5]], %[[VAL_4]], %[[VAL_6]], %[[VAL_8]], %[[VAL_7]] : (index, index, index, index, index, index) -> !fir.slice<2> -! CHECK: %[[VAL_11:.*]] = fir.embox %[[VAL_0]](%[[VAL_9]]) [%[[VAL_10]]] : (!fir.ref>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box> +! CHECK: %[[VAL_11:.*]] = fir.embox %[[VAL_0]](%[[VAL_9]]) [%[[VAL_10]]] : (!fir.ref>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box> ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_1]] : (!fir.ref) -> i64 ! CHECK: %[[c0_i64:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_13:.*]] = arith.cmpi eq, %[[VAL_12]], %[[c0_i64]] : i64 ! CHECK: %[[VAL_14:.*]] = fir.if %[[VAL_13]] -> (i64) { -! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_19:.*]] = fir.call @_FortranASize(%[[VAL_17]], %{{.*}}, %{{.*}}) : (!fir.box, !fir.ref, i32) -> i64 ! CHECK: fir.result %[[VAL_19]] : i64 ! CHECK: } else { ! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_1]] : !fir.ref -! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_20:.*]] = fir.call @_FortranASizeDim(%[[VAL_18]], %[[VAL_16]], %{{.*}}, %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 ! CHECK: fir.result %[[VAL_20]] : i64 ! CHECK: } diff --git a/flang/test/Lower/array-expression-slice-1.f90 b/flang/test/Lower/array-expression-slice-1.f90 --- a/flang/test/Lower/array-expression-slice-1.f90 +++ b/flang/test/Lower/array-expression-slice-1.f90 @@ -399,8 +399,8 @@ ! CHECK: %[[VAL_16:.*]] = fir.call @_FortranAioOutputAscii(%[[VAL_12]], %[[VAL_14]], %[[VAL_15]]) : (!fir.ref, !fir.ref, i64) -> i1 ! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_18:.*]] = fir.slice %[[VAL_3]], %[[VAL_1]], %[[VAL_2]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_19:.*]] = fir.embox %[[VAL_9]](%[[VAL_17]]) {{\[}}%[[VAL_18]]] : (!fir.ref>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box>> -! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (!fir.box>>) -> !fir.box +! CHECK: %[[VAL_19:.*]] = fir.embox %[[VAL_9]](%[[VAL_17]]) {{\[}}%[[VAL_18]]] : (!fir.ref>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box>> +! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (!fir.box>>) -> !fir.box ! CHECK: %[[VAL_21:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_12]], %[[VAL_20]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_12]]) : (!fir.ref) -> i32 ! CHECK: return diff --git a/flang/test/Lower/array-temp.f90 b/flang/test/Lower/array-temp.f90 --- a/flang/test/Lower/array-temp.f90 +++ b/flang/test/Lower/array-temp.f90 @@ -120,8 +120,8 @@ ! CHECK: fir.freemem %[[VAL_27]] : !fir.heap> ! CHECK: %[[VAL_58:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[VAL_8]], %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_59:.*]] = fir.slice %[[VAL_3]], %[[VAL_5]], %[[VAL_3]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_60:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_59]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> -! CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_60]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_60:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_59]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_60]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_62:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_58]], %[[VAL_61]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_63:.*]] = fir.load %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_64:.*]] = arith.subi %[[VAL_63]], %[[VAL_6]] : i32 @@ -246,8 +246,8 @@ ! CHECK: fir.freemem %[[VAL_33]] : !fir.heap> ! CHECK: %[[VAL_82:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[VAL_8]], %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_83:.*]] = fir.slice %[[VAL_3]], %[[VAL_2]], %[[VAL_3]], %[[VAL_3]], %[[VAL_2]], %[[VAL_3]] : (index, index, index, index, index, index) -> !fir.slice<2> -! CHECK: %[[VAL_84:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_83]]] : (!fir.ref>, !fir.shape<2>, !fir.slice<2>) -> !fir.box> -! CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_84]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_84:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_83]]] : (!fir.ref>, !fir.shape<2>, !fir.slice<2>) -> !fir.box> +! CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_84]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_86:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_82]], %[[VAL_85]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_87:.*]] = fir.load %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_88:.*]] = arith.subi %[[VAL_87]], %[[VAL_6]] : i32 @@ -372,8 +372,8 @@ ! CHECK: fir.freemem %[[VAL_33]] : !fir.heap> ! CHECK: %[[VAL_82:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[VAL_8]], %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_83:.*]] = fir.slice %[[VAL_3]], %[[VAL_2]], %[[VAL_3]], %[[VAL_3]], %[[VAL_2]], %[[VAL_3]] : (index, index, index, index, index, index) -> !fir.slice<2> -! CHECK: %[[VAL_84:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_83]]] : (!fir.ref>, !fir.shape<2>, !fir.slice<2>) -> !fir.box> -! CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_84]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_84:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) {{\[}}%[[VAL_83]]] : (!fir.ref>, !fir.shape<2>, !fir.slice<2>) -> !fir.box> +! CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_84]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_86:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_82]], %[[VAL_85]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_87:.*]] = fir.load %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_88:.*]] = arith.subi %[[VAL_87]], %[[VAL_6]] : i32 diff --git a/flang/test/Lower/call-by-value-attr.f90 b/flang/test/Lower/call-by-value-attr.f90 --- a/flang/test/Lower/call-by-value-attr.f90 +++ b/flang/test/Lower/call-by-value-attr.f90 @@ -66,17 +66,17 @@ !CHECK: %[[CONV_15:.*]] = fir.convert %[[CONST_15_3]] : (i64) -> index !CHECK: %[[SHAPE_7:.*]] = fir.shape %[[CONST_15_1]] : (index) -> !fir.shape<1> !CHECK: %[[SLICE:.*]] = fir.slice %[[CONV_5]], %[[CONV_15]], %[[CONV_1]] : (index, index, index) -> !fir.slice<1> - !CHECK: %[[BOX:.*]] = fir.embox %[[ARRAY_B]](%[[SHAPE_7]]) [%[[SLICE]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> + !CHECK: %[[BOX:.*]] = fir.embox %[[ARRAY_B]](%[[SHAPE_7]]) [%[[SLICE]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> !CHECK: %[[CONST_0:.*]] = arith.constant 0 : index - !CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[BOX]], %[[CONST_0]] : (!fir.box>, index) -> (index, index, index) - !CHECK: %[[ARRAY_COPY_2:.*]] = fir.allocmem !fir.array, %[[DIMS]]#1 {uniq_name = ".copy"} + !CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[BOX]], %[[CONST_0]] : (!fir.box>, index) -> (index, index, index) + !CHECK: %[[ARRAY_COPY_2:.*]] = fir.allocmem !fir.array<11xi32>, %[[DIMS]]#1 {uniq_name = ".copy"} !CHECK: %[[SHAPE_8:.*]] = fir.shape %[[DIMS]]#1 : (index) -> !fir.shape<1> - !CHECK: %[[ARRAY_LOAD_7:.*]] = fir.array_load %[[ARRAY_COPY_2]](%[[SHAPE_8]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array - !CHECK: %[[ARRAY_LOAD_8:.*]] = fir.array_load %[[BOX]] : (!fir.box>) -> !fir.array + !CHECK: %[[ARRAY_LOAD_7:.*]] = fir.array_load %[[ARRAY_COPY_2]](%[[SHAPE_8]]) : (!fir.heap>, !fir.shape<1>) -> !fir.array<11xi32> + !CHECK: %[[ARRAY_LOAD_8:.*]] = fir.array_load %[[BOX]] : (!fir.box>) -> !fir.array<11xi32> !CHECK: %[[DO_4:.*]] = fir.do_loop {{.*}} { !CHECK: } - !CHECK fir.array_merge_store %[[ARRAY_LOAD_7]], %[[DO_4]] to %[[ARRAY_COPY_2]] : !fir.array, !fir.array, !fir.heap> - !CHECK: %[[CONVERT_B:.*]] = fir.convert %[[ARRAY_COPY_2]] : (!fir.heap>) -> !fir.ref> + !CHECK fir.array_merge_store %[[ARRAY_LOAD_7]], %[[DO_4]] to %[[ARRAY_COPY_2]] : !fir.array<11xi32>, !fir.array<11xi32>, !fir.heap> + !CHECK: %[[CONVERT_B:.*]] = fir.convert %[[ARRAY_COPY_2]] : (!fir.heap>) -> !fir.ref> !CHECK: fir.call @_QPsubra(%[[CONVERT_B]]) call subra(b(5:15)) end program call_by_value_attr diff --git a/flang/test/Lower/components.f90 b/flang/test/Lower/components.f90 --- a/flang/test/Lower/components.f90 +++ b/flang/test/Lower/components.f90 @@ -79,8 +79,9 @@ ! CHECK: %[[VAL_14:.*]] = arith.subi %[[VAL_10]], %[[VAL_1]] : index ! CHECK: br ^bb1(%[[VAL_12]], %[[VAL_14]] : index, index) ! CHECK: ^bb3: -! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_5]](%[[VAL_7]]) {{\[}}%[[VAL_8]]] : (!fir.ref>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> -! CHECK: fir.call @_QPtakes_int_array(%[[VAL_15]]) : (!fir.box>) -> () +! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_5]](%[[VAL_7]]) {{\[}}%[[VAL_8]]] : (!fir.ref>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (!fir.box>) -> !fir.box> +! CHECK: fir.call @_QPtakes_int_array(%[[VAL_16]]) : (!fir.box>) -> () ! CHECK: return ! CHECK: } @@ -292,7 +293,7 @@ ! CHECK: %[[VAL_50:.*]] = fir.call @_FortranAioBeginExternalListOutput(%{{.*}}, %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_51:.*]] = fir.slice %c1{{.*}}, %c5{{.*}}, %c1{{.*}} path %{{.*}}, %{{.*}} : (index, index, index, !fir.field, !fir.field) -> !fir.slice<1> ! CHECK: %[[VAL_52:.*]] = fir.embox %[[u3va]](%{{.*}}) [%[[VAL_51]]] : (!fir.ref,u2t4:!fir.type<_QFextended_type_componentsTt3{t1i:i32,t2i:i32,t3i:i32}>,u3i:i32}>>>, - ! CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_52]] : (!fir.box>) -> !fir.box + ! CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_52]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_54:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_50]], %[[VAL_53]]) : (!fir.ref, !fir.box) -> i1 print*, u3va%u2t3%t1i @@ -302,15 +303,15 @@ ! CHECK: %[[VAL_70:.*]] = fir.call @_FortranAioBeginExternalListOutput(%{{.*}}, %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_71:.*]] = fir.slice %c1{{.*}}, %c5{{.*}}, %c1{{.*}} path %{{.*}}, %{{.*}} : (index, index, index, !fir.field, !fir.field) -> !fir.slice<1> - ! CHECK: %[[VAL_72:.*]] = fir.embox %[[u3va]](%{{.*}}) [%[[VAL_71]]] : (!fir.ref,u2t4:!fir.type<_QFextended_type_componentsTt3{t1i:i32,t2i:i32,t3i:i32}>,u3i:i32}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> - ! CHECK: %[[VAL_73:.*]] = fir.convert %[[VAL_72]] : (!fir.box>) -> !fir.box + ! CHECK: %[[VAL_72:.*]] = fir.embox %[[u3va]](%{{.*}}) [%[[VAL_71]]] : (!fir.ref,u2t4:!fir.type<_QFextended_type_componentsTt3{t1i:i32,t2i:i32,t3i:i32}>,u3i:i32}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> + ! CHECK: %[[VAL_73:.*]] = fir.convert %[[VAL_72]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_74:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_70]], %[[VAL_73]]) : (!fir.ref, !fir.box) -> i1 print*, u3va%u2t4%t1i ! CHECK: %[[VAL_80:.*]] = fir.call @_FortranAioBeginExternalListOutput(%{{.*}}, %{{.*}}, %{{.*}}) : (i32, !fir.ref, i32) -> !fir.ref ! CHECK: %[[VAL_81:.*]] = fir.slice %c1{{.*}}, %c5{{.*}}, %c1{{.*}} path %{{.*}}, %{{.*}} : (index, index, index, !fir.field, !fir.field) -> !fir.slice<1> - ! CHECK: %[[VAL_82:.*]] = fir.embox %[[u3va]](%{{.*}}) [%[[VAL_81]]] : (!fir.ref,u2t4:!fir.type<_QFextended_type_componentsTt3{t1i:i32,t2i:i32,t3i:i32}>,u3i:i32}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> - ! CHECK: %[[VAL_83:.*]] = fir.convert %[[VAL_82]] : (!fir.box>) -> !fir.box + ! CHECK: %[[VAL_82:.*]] = fir.embox %[[u3va]](%{{.*}}) [%[[VAL_81]]] : (!fir.ref,u2t4:!fir.type<_QFextended_type_componentsTt3{t1i:i32,t2i:i32,t3i:i32}>,u3i:i32}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> + ! CHECK: %[[VAL_83:.*]] = fir.convert %[[VAL_82]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_84:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_80]], %[[VAL_83]]) : (!fir.ref, !fir.box) -> i1 print*, u3va%u2t4%t2i end subroutine extended_type_components diff --git a/flang/test/Lower/derived-allocatable-components.f90 b/flang/test/Lower/derived-allocatable-components.f90 --- a/flang/test/Lower/derived-allocatable-components.f90 +++ b/flang/test/Lower/derived-allocatable-components.f90 @@ -136,8 +136,9 @@ ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i64) -> index ! CHECK: %[[VAL_14:.*]] = fir.shape_shift %[[VAL_6]]#0, %[[VAL_6]]#1 : (index, index) -> !fir.shapeshift<1> ! CHECK: %[[VAL_15:.*]] = fir.slice %[[VAL_9]], %[[VAL_13]], %[[VAL_11]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_16:.*]] = fir.embox %[[VAL_7]](%[[VAL_14]]) {{\[}}%[[VAL_15]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> -! CHECK: fir.call @_QPtakes_real_array(%[[VAL_16]]) : (!fir.box>) -> () +! CHECK: %[[VAL_16:.*]] = fir.embox %[[VAL_7]](%[[VAL_14]]) {{\[}}%[[VAL_15]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_16_NEW:.*]] = fir.convert %[[VAL_16]] : (!fir.box>) -> !fir.box> +! CHECK: fir.call @_QPtakes_real_array(%[[VAL_16_NEW]]) : (!fir.box>) -> () ! CHECK: %[[VAL_17:.*]] = arith.constant 5 : i64 ! CHECK: %[[VAL_18:.*]] = arith.constant 1 : i64 ! CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_17]], %[[VAL_18]] : i64 @@ -156,8 +157,9 @@ ! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_31]] : (i64) -> index ! CHECK: %[[VAL_33:.*]] = fir.shape_shift %[[VAL_25]]#0, %[[VAL_25]]#1 : (index, index) -> !fir.shapeshift<1> ! CHECK: %[[VAL_34:.*]] = fir.slice %[[VAL_28]], %[[VAL_32]], %[[VAL_30]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_35:.*]] = fir.embox %[[VAL_26]](%[[VAL_33]]) {{\[}}%[[VAL_34]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> -! CHECK: fir.call @_QPtakes_real_array(%[[VAL_35]]) : (!fir.box>) -> () +! CHECK: %[[VAL_35:.*]] = fir.embox %[[VAL_26]](%[[VAL_33]]) {{\[}}%[[VAL_34]]] : (!fir.heap>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_35_NEW:.*]] = fir.convert %[[VAL_35]] : (!fir.box>) -> !fir.box> +! CHECK: fir.call @_QPtakes_real_array(%[[VAL_35_NEW]]) : (!fir.box>) -> () ! CHECK: return ! CHECK: } diff --git a/flang/test/Lower/derived-pointer-components.f90 b/flang/test/Lower/derived-pointer-components.f90 --- a/flang/test/Lower/derived-pointer-components.f90 +++ b/flang/test/Lower/derived-pointer-components.f90 @@ -133,8 +133,9 @@ ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index ! CHECK: %[[VAL_13:.*]] = fir.shift %[[VAL_6]]#0 : (index) -> !fir.shift<1> ! CHECK: %[[VAL_14:.*]] = fir.slice %[[VAL_8]], %[[VAL_12]], %[[VAL_10]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_15:.*]] = fir.rebox %[[VAL_4]](%[[VAL_13]]) {{\[}}%[[VAL_14]]] : (!fir.box>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> -! CHECK: fir.call @_QPtakes_real_array(%[[VAL_15]]) : (!fir.box>) -> () +! CHECK: %[[VAL_15:.*]] = fir.rebox %[[VAL_4]](%[[VAL_13]]) {{\[}}%[[VAL_14]]] : (!fir.box>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_15_NEW:.*]] = fir.convert %[[VAL_15]] : (!fir.box>) -> !fir.box> +! CHECK: fir.call @_QPtakes_real_array(%[[VAL_15_NEW]]) : (!fir.box>) -> () ! CHECK: %[[VAL_16:.*]] = arith.constant 5 : i64 ! CHECK: %[[VAL_17:.*]] = arith.constant 1 : i64 ! CHECK: %[[VAL_18:.*]] = arith.subi %[[VAL_16]], %[[VAL_17]] : i64 @@ -152,8 +153,9 @@ ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i64) -> index ! CHECK: %[[VAL_31:.*]] = fir.shift %[[VAL_24]]#0 : (index) -> !fir.shift<1> ! CHECK: %[[VAL_32:.*]] = fir.slice %[[VAL_26]], %[[VAL_30]], %[[VAL_28]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_33:.*]] = fir.rebox %[[VAL_22]](%[[VAL_31]]) {{\[}}%[[VAL_32]]] : (!fir.box>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> -! CHECK: fir.call @_QPtakes_real_array(%[[VAL_33]]) : (!fir.box>) -> () +! CHECK: %[[VAL_33:.*]] = fir.rebox %[[VAL_22]](%[[VAL_31]]) {{\[}}%[[VAL_32]]] : (!fir.box>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_33_NEW:.*]] = fir.convert %[[VAL_33]] : (!fir.box>) -> !fir.box> +! CHECK: fir.call @_QPtakes_real_array(%[[VAL_33_NEW]]) : (!fir.box>) -> () ! CHECK: return ! CHECK: } @@ -756,7 +758,7 @@ ! CHECK: %[[VAL_17:.*]] = arith.select %[[VAL_16]], %[[VAL_15]], %[[VAL_12]] : index ! CHECK: %[[VAL_18:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_19:.*]] = fir.slice %[[VAL_7]], %[[VAL_11]], %[[VAL_9]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_20:.*]] = fir.embox %[[VAL_2]](%[[VAL_18]]) {{\[}}%[[VAL_19]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_20:.*]] = fir.embox %[[VAL_2]](%[[VAL_18]]) {{\[}}%[[VAL_19]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> ! CHECK: %[[VAL_21:.*]] = fir.embox %[[VAL_2]](%[[VAL_18]]) {{\[}}%[[VAL_19]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box>> ! CHECK: %[[VAL_22:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_21]], ["p", !fir.type<_QMpcompTreal_p1{p:!fir.box>>}>] : (!fir.type<_QMpcompTreal_p1{p:!fir.box>>}>, !fir.box>>) -> !fir.type<_QMpcompTreal_p1{p:!fir.box>>}> ! CHECK: fir.has_value %[[VAL_22]] : !fir.type<_QMpcompTreal_p1{p:!fir.box>>}> diff --git a/flang/test/Lower/io-item-list.f90 b/flang/test/Lower/io-item-list.f90 --- a/flang/test/Lower/io-item-list.f90 +++ b/flang/test/Lower/io-item-list.f90 @@ -40,8 +40,8 @@ ! CHECK: %[[VAL_10:.*]] = arith.constant 200 : i64 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i64) -> index ! CHECK: %[[VAL_12:.*]] = fir.slice %[[VAL_7]], %[[VAL_11]], %[[VAL_9]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_13:.*]] = fir.rebox %[[VAL_0]] {{\[}}%[[VAL_12]]] : (!fir.box>, !fir.slice<1>) -> !fir.box> -! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_13:.*]] = fir.rebox %[[VAL_0]] {{\[}}%[[VAL_12]]] : (!fir.box>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_15:.*]] = fir.call @_FortranAioInputDescriptor(%[[VAL_5]], %[[VAL_14]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_16:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_5]]) : (!fir.ref) -> i32 ! CHECK: return @@ -69,8 +69,8 @@ ! CHECK: %[[VAL_13:.*]] = arith.constant 200 : i64 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i64) -> index ! CHECK: %[[VAL_15:.*]] = fir.slice %[[VAL_10]], %[[VAL_14]], %[[VAL_12]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_16:.*]] = fir.rebox %[[VAL_0]] {{\[}}%[[VAL_15]]] : (!fir.box>, !fir.slice<1>) -> !fir.box> -! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_16:.*]] = fir.rebox %[[VAL_0]] {{\[}}%[[VAL_15]]] : (!fir.box>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAioOutputDescriptor(%[[VAL_5]], %[[VAL_17]]) : (!fir.ref, !fir.box) -> i1 ! CHECK: %[[VAL_19:.*]] = fir.call @_FortranAioEndIoStatement(%[[VAL_5]]) : (!fir.ref) -> i32 ! CHECK: return diff --git a/flang/test/Lower/pointer-assignments.f90 b/flang/test/Lower/pointer-assignments.f90 --- a/flang/test/Lower/pointer-assignments.f90 +++ b/flang/test/Lower/pointer-assignments.f90 @@ -145,7 +145,6 @@ ! CHECK: %[[c7_idx:.*]] = fir.convert %c7{{.*}} : (i64) -> index ! CHECK: %[[shift:.*]] = fir.shift %[[c7_idx]] : (index) -> !fir.shift<1> ! CHECK: %[[rebox:.*]] = fir.rebox %[[x]](%[[shift]]) : (!fir.box>, !fir.shift<1>) -> !fir.box>> - ! CHECK: fir.store %[[rebox]] to %[[p]] : !fir.ref>>> p => x end subroutine @@ -161,8 +160,8 @@ ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index ! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_10:.*]] = fir.slice %[[VAL_4]], %[[VAL_8]], %[[VAL_6]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_11:.*]] = fir.embox %[[VAL_1]](%[[VAL_9]]) {{\[}}%[[VAL_10]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> -! CHECK: %[[VAL_12:.*]] = fir.rebox %[[VAL_11]] : (!fir.box>) -> !fir.box>> +! CHECK: %[[VAL_11:.*]] = fir.embox %[[VAL_1]](%[[VAL_9]]) {{\[}}%[[VAL_10]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_12:.*]] = fir.rebox %[[VAL_11]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.store %[[VAL_12]] to %[[VAL_0]] : !fir.ref>>> ! CHECK: return ! CHECK: } @@ -225,7 +224,7 @@ ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index ! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_14:.*]] = fir.slice %[[VAL_8]], %[[VAL_12]], %[[VAL_10]] : (index, index, index) -> !fir.slice<1> -! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_1]](%[[VAL_13]]) {{\[}}%[[VAL_14]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_1]](%[[VAL_13]]) {{\[}}%[[VAL_14]]] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box> ! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_3]] : (i64) -> index ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_4]] : (i64) -> index @@ -238,7 +237,7 @@ ! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_3]] : (i64) -> index ! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_5]] : (i64) -> index ! CHECK: %[[VAL_27:.*]] = fir.shape_shift %[[VAL_25]], %[[VAL_20]], %[[VAL_26]], %[[VAL_24]] : (index, index, index, index) -> !fir.shapeshift<2> -! CHECK: %[[VAL_28:.*]] = fir.rebox %[[VAL_15]](%[[VAL_27]]) : (!fir.box>, !fir.shapeshift<2>) -> !fir.box>> +! CHECK: %[[VAL_28:.*]] = fir.rebox %[[VAL_15]](%[[VAL_27]]) : (!fir.box>, !fir.shapeshift<2>) -> !fir.box>> ! CHECK: fir.store %[[VAL_28]] to %[[VAL_0]] : !fir.ref>>> ! CHECK: return ! CHECK: } @@ -331,10 +330,10 @@ ! CHECK-DAG: %[[lhs2_len:.*]] = fir.alloca index {uniq_name = "_QFissue857_charElhs2.len"} character(:), contiguous, pointer :: lhs1(:), lhs2(:, :) character(*), target :: rhs(100) - ! CHECK: %[[len:.*]] = fir.box_elesize %{{.*}} : (!fir.box>>) -> index + ! CHECK: %[[len:.*]] = fir.box_elesize %{{.*}} : (!fir.box>>) -> index ! CHECK: fir.store %[[len]] to %[[lhs1_len]] : !fir.ref lhs1 => rhs(1:50:1) - ! CHECK: %[[len2:.*]] = fir.box_elesize %{{.*}} : (!fir.box>>) -> index + ! CHECK: %[[len2:.*]] = fir.box_elesize %{{.*}} : (!fir.box>>) -> index ! CHECK: fir.store %[[len2]] to %[[lhs2_len]] : !fir.ref lhs2(1:2, 1:25) => rhs(1:50:1) end subroutine diff --git a/flang/test/Lower/pointer-initial-target.f90 b/flang/test/Lower/pointer-initial-target.f90 --- a/flang/test/Lower/pointer-initial-target.f90 +++ b/flang/test/Lower/pointer-initial-target.f90 @@ -179,7 +179,7 @@ ! CHECK: %[[VAL_22:.*]] = arith.select %[[VAL_21]], %[[VAL_20]], %[[VAL_17]] : index ! CHECK: %[[VAL_23:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2> ! CHECK: %[[VAL_24:.*]] = fir.slice %[[VAL_7]], %[[VAL_8]], %[[VAL_8]], %[[VAL_12]], %[[VAL_16]], %[[VAL_14]] : (i64, index, index, index, index, index) -> !fir.slice<2> -! CHECK: %[[VAL_25:.*]] = fir.embox %[[VAL_0]](%[[VAL_23]]) {{\[}}%[[VAL_24]]] : (!fir.ref>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box> +! CHECK: %[[VAL_25:.*]] = fir.embox %[[VAL_0]](%[[VAL_23]]) {{\[}}%[[VAL_24]]] : (!fir.ref>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box> ! CHECK: %[[VAL_26:.*]] = fir.embox %[[VAL_0]](%[[VAL_23]]) {{\[}}%[[VAL_24]]] : (!fir.ref>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box>> ! CHECK: fir.has_value %[[VAL_26]] : !fir.box>> ! CHECK: } diff --git a/flang/test/Lower/structure-constructors.f90 b/flang/test/Lower/structure-constructors.f90 --- a/flang/test/Lower/structure-constructors.f90 +++ b/flang/test/Lower/structure-constructors.f90 @@ -150,8 +150,8 @@ ! CHECK: %[[VAL_19:.*]] = arith.constant 3 : i64 ! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (i64) -> index ! CHECK: %[[VAL_21:.*]] = fir.slice %[[VAL_10]], %[[VAL_14]], %[[VAL_12]], %[[VAL_16]], %[[VAL_20]], %[[VAL_18]] : (index, index, index, index, index, index) -> !fir.slice<2> - ! CHECK: %[[VAL_22:.*]] = fir.rebox %[[VAL_1]] {{\[}}%[[VAL_21]]] : (!fir.box>, !fir.slice<2>) -> !fir.box> - ! CHECK: %[[VAL_23:.*]] = fir.rebox %[[VAL_22]] : (!fir.box>) -> !fir.box>> + ! CHECK: %[[VAL_22:.*]] = fir.rebox %[[VAL_1]] {{\[}}%[[VAL_21]]] : (!fir.box>, !fir.slice<2>) -> !fir.box> + ! CHECK: %[[VAL_23:.*]] = fir.rebox %[[VAL_22]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.store %[[VAL_23]] to %[[VAL_8]] : !fir.ref>>> ! CHECK: fir.call @_QMm_struct_ctorPprint_ptr(%[[VAL_3]]) : (!fir.ref>>}>>) -> () ! CHECK: return