diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -737,6 +737,10 @@ {"kind", asValue}}}}, {"ishft", &I::genIshft}, {"ishftc", &I::genIshftc}, + {"lbound", + &I::genLbound, + {{{"array", asInquired}, {"dim", asValue}, {"kind", asValue}}}, + /*isElemental=*/false}, {"len", &I::genLen, {{{"string", asInquired}, {"kind", asValue}}}, diff --git a/flang/test/Lower/Intrinsics/lbound.f90 b/flang/test/Lower/Intrinsics/lbound.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/Intrinsics/lbound.f90 @@ -0,0 +1,54 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + + +! CHECK-LABEL: func @_QPlbound_test( +! CHECK: %[[VAL_0:.*]] = fir.load %arg1 : !fir.ref +! CHECK: %[[VAL_1:.*]] = fir.rebox %arg0 : (!fir.box>) -> !fir.box> +subroutine lbound_test(a, dim, res) + real, dimension(:, :) :: a + integer(8):: dim, res +! CHECK: %[[VAL_2:.*]] = fir.address_of( +! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_1]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32 +! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_2]] +! CHECK: %[[VAL_6:.*]] = fir.call @_FortranALboundDim(%[[VAL_3]], %[[VAL_4]], %[[VAL_5]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: fir.store %[[VAL_6]] to %arg2 : !fir.ref + res = lbound(a, dim, 8) +end subroutine + +! CHECK-LABEL: func @_QPlbound_test_2( +! CHECK: %[[VAL_c1_i64:.*]] = arith.constant 1 : i64 +! CHECK: %[[VAL_0:.*]] = fir.convert %[[VAL_c1_i64]] : (i64) -> index +! CHECK: %[[VAL_c2_i64:.*]] = arith.constant 2 : i64 +! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_c2_i64]] : (i64) -> index +! CHECK: %[[VAL_2:.*]] = fir.load %arg1 : !fir.ref +subroutine lbound_test_2(a, dim, res) + real, dimension(:, 2:) :: a + integer(8):: dim, res +! CHECK: %[[VAL_3:.*]] = fir.shift %[[VAL_0]], %[[VAL_1]] : (index, index) -> !fir.shift<2> +! CHECK: %[[VAL_4:.*]] = fir.rebox %arg0(%[[VAL_3]]) : (!fir.box>, !fir.shift<2>) -> !fir.box> +! CHECK: %[[VAL_5:.*]] = fir.address_of( +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_4]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (i64) -> i32 +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_5]] +! CHECK: %[[VAL_9:.*]] = fir.call @_FortranALboundDim(%[[VAL_6]], %[[VAL_7]], %[[VAL_8]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: fir.store %[[VAL_9]] to %arg2 : !fir.ref + res = lbound(a, dim, 8) +end subroutine + +! CHECK: %[[VAL_0:.*]] = fir.undefined index +subroutine lbound_test_3(a, dim, res) + real, dimension(2:10, 3:*) :: a + integer(8):: dim, res +! CHECK: %[[VAL_1:.*]] = fir.load %arg1 : !fir.ref +! CHECK: %[[VAL_2:.*]] = fir.shape_shift %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_0]] : (index, index, index, index) -> !fir.shapeshift<2> +! CHECK: %[[VAL_3:.*]] = fir.embox %arg0(%[[VAL_2]]) : (!fir.ref>, !fir.shapeshift<2>) -> !fir.box> +! CHECK: %[[VAL_4:.*]] = fir.address_of( +! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_1]] : (i64) -> i32 +! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] +! CHECK: %[[VAL_8:.*]] = fir.call @_FortranALboundDim(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: fir.store %[[VAL_8]] to %arg2 : !fir.ref + res = lbound(a, dim, 8) +end subroutine diff --git a/flang/test/Lower/Intrinsics/ubound.f90 b/flang/test/Lower/Intrinsics/ubound.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/Intrinsics/ubound.f90 @@ -0,0 +1,71 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: func @_QPubound_test( +subroutine ubound_test(a, dim, res) + real, dimension(:, :) :: a + integer(8):: dim, res +! CHECK: %[[VAL_0:.*]] = fir.load +! CHECK: %[[VAL_1:.*]] = fir.address_of( +! CHECK: %[[VAL_2:.*]] = fir.convert +! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32 +! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] +! CHECK: %[[VAL_5:.*]] = fir.call @_FortranASizeDim(%[[VAL_2]], %[[VAL_3]], %[[VAL_4]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_6:.*]] = fir.address_of( +! CHECK: %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32 +! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]] +! CHECK: %[[VAL_10:.*]] = fir.call @_FortranALboundDim(%[[VAL_7]], %[[VAL_8]], %[[VAL_9]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %c1_i64 : i64 +! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_5]] : i64 + +! CHECK: fir.store %[[VAL_12]] to %{{.*}} : !fir.ref + res = ubound(a, dim, 8) +end subroutine + +! CHECK-LABEL: func @_QPubound_test_2( +subroutine ubound_test_2(a, dim, res) + real, dimension(2:, 3:) :: a + integer(8):: dim, res +! CHECK: %[[VAL_0:.*]] = fir.load %{{.*}} : !fir.ref +! CHECK: %[[VAL_1:.*]] = fir.address_of( +! CHECK: %[[VAL_2:.*]] = fir.convert %{{.*}} : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32 +! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] +! CHECK: %[[VAL_5:.*]] = fir.call @_FortranASizeDim(%[[VAL_2]], %[[VAL_3]], %[[VAL_4]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_6:.*]] = fir.address_of( +! CHECK: %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_0]] : (i64) -> i32 +! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]] +! CHECK: %[[VAL_10:.*]] = fir.call @_FortranALboundDim(%[[VAL_7]], %[[VAL_8]], %[[VAL_9]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %{{.*}} : i64 +! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_5]] : i64 +! CHECK: fir.store %[[VAL_12]] to %{{.*}} : !fir.ref + res = ubound(a, dim, 8) +end subroutine + +! CHECK-LABEL: func @_QPubound_test_3( +subroutine ubound_test_3(a, dim, res) + real, dimension(10, 20, *) :: a + integer(8):: dim, res +! CHECK: %[[VAL_0:.*]] = fir.undefined index +! CHECK: %[[VAL_1:.*]] = fir.shape %{{.*}}, %{{.*}}, %[[VAL_0]] : (index, index, index) -> !fir.shape<3> +! CHECK: %[[VAL_2:.*]] = fir.embox %{{.*}}(%[[VAL_1]]) : (!fir.ref>, !fir.shape<3>) -> !fir.box> +! CHECK: %[[VAL_3:.*]] = fir.load %{{.*}} : !fir.ref +! CHECK: %[[VAL_4:.*]] = fir.address_of( +! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_2]] : (!fir.box>) -> !fir.box + +! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_3]] : (i64) -> i32 +! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] +! CHECK: %[[VAL_8:.*]] = fir.call @_FortranASizeDim(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_9:.*]] = fir.rebox %[[VAL_2]] : (!fir.box>) -> !fir.box> +! CHECK: %[[VAL_10:.*]] = fir.address_of( +! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_9]] : (!fir.box>) -> !fir.box +! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_3]] +! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_10]] +! CHECK: %[[VAL_14:.*]] = fir.call @_FortranALboundDim(%[[VAL_11]], %[[VAL_12]], %[[VAL_13]], %{{.*}}) : (!fir.box, i32, !fir.ref, i32) -> i64 +! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %{{.*}} : i64 +! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_15]], %[[VAL_8]] : i64 +! CHECK: fir.store %[[VAL_16]] to %{{.*}} : !fir.ref + res = ubound(a, dim, 8) +end subroutine