[flang-commits] [flang] [flang][NFC] Converted five tests from old lowering to new lowering (part 43) (PR #191753)

via flang-commits flang-commits at lists.llvm.org
Sun Apr 12 20:21:16 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Eugene Epshteyn (eugeneepshteyn)

<details>
<summary>Changes</summary>

Tests converted from test/Lower/Intrinsics: transpose.f90, transpose_opt.f90, trim.f90, ubound.f90, ubound01.f90

---

Patch is 22.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/191753.diff


5 Files Affected:

- (modified) flang/test/Lower/Intrinsics/transpose.f90 (+9-19) 
- (modified) flang/test/Lower/Intrinsics/transpose_opt.f90 (+11-84) 
- (modified) flang/test/Lower/Intrinsics/trim.f90 (+9-13) 
- (modified) flang/test/Lower/Intrinsics/ubound.f90 (+31-53) 
- (modified) flang/test/Lower/Intrinsics/ubound01.f90 (+3-2) 


``````````diff
diff --git a/flang/test/Lower/Intrinsics/transpose.f90 b/flang/test/Lower/Intrinsics/transpose.f90
index cf2c2ba5bde83..9e0fb5fff2f82 100644
--- a/flang/test/Lower/Intrinsics/transpose.f90
+++ b/flang/test/Lower/Intrinsics/transpose.f90
@@ -1,25 +1,15 @@
-! RUN: bbc -emit-fir -hlfir=false %s -opt-transpose=false -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -O0 %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 ! CHECK-LABEL: func @_QPtranspose_test(
-! CHECK-SAME: %[[source:.*]]: !fir.ref<!fir.array<2x3xf32>>{{.*}}) {
+! CHECK-SAME: %[[mat:.*]]: !fir.ref<!fir.array<2x3xf32>>{{.*}})
 subroutine transpose_test(mat)
-! CHECK:  %[[resultDescr:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x?xf32>>>
    real :: mat(2,3)
    call bar_transpose_test(transpose(mat))
-! CHECK:  %[[sourceBox:.*]] = fir.embox %[[source]]({{.*}}) : (!fir.ref<!fir.array<2x3xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<2x3xf32>>
-! CHECK:  %[[zeroArray:.*]] = fir.zero_bits !fir.heap<!fir.array<?x?xf32>
-! CHECK:  %[[c0:.*]] = arith.constant 0 : index
-! CHECK:  %[[shapeResult:.*]] = fir.shape %[[c0]], %[[c0]] : (index, index) -> !fir.shape<2>
-! CHECK:  %[[resultBox:.*]] = fir.embox %[[zeroArray]](%[[shapeResult]]) : (!fir.heap<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.heap<!fir.array<?x?xf32>>>
-! CHECK:  fir.store %[[resultBox]] to %[[resultDescr]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
-! CHECK:  %[[resultOpaque:.*]] = fir.convert %[[resultDescr]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<none>>
-! CHECK:  %[[sourceOpaque:.*]] = fir.convert %[[sourceBox]] : (!fir.box<!fir.array<2x3xf32>>) -> !fir.box<none>
-! CHECK:  fir.call @_FortranATranspose(%[[resultOpaque]], %[[sourceOpaque]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> ()
-! CHECK:  %[[tmp1:.*]] = fir.load %[[resultDescr]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
-! CHECK:  %[[tmp2:.*]] = fir.box_addr %[[tmp1]] : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !fir.heap<!fir.array<?x?xf32>>
-! CHECK:  %[[tmp3:.*]] = fir.convert %[[tmp2]] : (!fir.heap<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<3x2xf32>>
-! CHECK:  fir.call @_QPbar_transpose_test(%[[tmp3]]) {{.*}}: (!fir.ref<!fir.array<3x2xf32>>) -> ()
-! CHECK:  fir.freemem %[[tmp2]] : !fir.heap<!fir.array<?x?xf32>
+! CHECK: %[[matDecl:.*]]:2 = hlfir.declare %[[mat]](%{{.*}}) {{.*}}{uniq_name = "_QFtranspose_testEmat"}
+! CHECK: %[[result:.*]] = hlfir.transpose %[[matDecl]]#0 : (!fir.ref<!fir.array<2x3xf32>>) -> !hlfir.expr<3x2xf32>
+! CHECK: %[[shape:.*]] = hlfir.shape_of %[[result]] : (!hlfir.expr<3x2xf32>) -> !fir.shape<2>
+! CHECK: %[[assoc:.*]]:3 = hlfir.associate %[[result]](%[[shape]]) {adapt.valuebyref}
+! CHECK: fir.call @_QPbar_transpose_test(%[[assoc]]#0)
+! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2
+! CHECK: hlfir.destroy %[[result]] : !hlfir.expr<3x2xf32>
 end subroutine
-
diff --git a/flang/test/Lower/Intrinsics/transpose_opt.f90 b/flang/test/Lower/Intrinsics/transpose_opt.f90
index 65102d1f8912f..f85daa965a1f8 100644
--- a/flang/test/Lower/Intrinsics/transpose_opt.f90
+++ b/flang/test/Lower/Intrinsics/transpose_opt.f90
@@ -1,98 +1,25 @@
-! RUN: bbc -emit-fir -hlfir=false %s -opt-transpose=true -o - | FileCheck %s
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -O1 %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -O2 %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -O3 %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 ! CHECK-LABEL: func.func @_QPtranspose_test(
-! CHECK-SAME:                               %[[VAL_0:.*]]: !fir.ref<!fir.array<2x3xf32>> {fir.bindc_name = "mat"}) {
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<2x3xf32>>{{.*}})
 subroutine transpose_test(mat)
    real :: mat(2,3)
    call bar_transpose_test(transpose(mat))
-! CHECK:         %[[VAL_6:.*]] = fir.array_load %[[VAL_0]](%{{.*}}) : (!fir.ref<!fir.array<2x3xf32>>, !fir.shape<2>) -> !fir.array<2x3xf32>
-! CHECK:         %[[VAL_7:.*]] = fir.allocmem !fir.array<3x2xf32>
-! CHECK:         %[[VAL_9:.*]] = fir.array_load %[[VAL_7]](%{{.*}}) : (!fir.heap<!fir.array<3x2xf32>>, !fir.shape<2>) -> !fir.array<3x2xf32>
-! CHECK:         %[[VAL_14:.*]] = fir.do_loop %[[VAL_15:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_16:.*]] = %[[VAL_9]]) -> (!fir.array<3x2xf32>) {
-! CHECK:           %[[VAL_17:.*]] = fir.do_loop %[[VAL_18:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_19:.*]] = %[[VAL_16]]) -> (!fir.array<3x2xf32>) {
-! CHECK:             %[[VAL_20:.*]] = fir.array_fetch %[[VAL_6]], %[[VAL_15]], %[[VAL_18]] : (!fir.array<2x3xf32>, index, index) -> f32
-! CHECK:             %[[VAL_21:.*]] = fir.array_update %[[VAL_19]], %[[VAL_20]], %[[VAL_18]], %[[VAL_15]] : (!fir.array<3x2xf32>, f32, index, index) -> !fir.array<3x2xf32>
-! CHECK:             fir.result %[[VAL_21]] : !fir.array<3x2xf32>
-! CHECK:           }
-! CHECK:           fir.result %[[VAL_17]] : !fir.array<3x2xf32>
-! CHECK:         }
-! CHECK:         fir.array_merge_store %[[VAL_9]], %[[VAL_14]] to %[[VAL_7]] : !fir.array<3x2xf32>, !fir.array<3x2xf32>, !fir.heap<!fir.array<3x2xf32>>
-! CHECK:         %[[VAL_24:.*]] = fir.convert %[[VAL_7]] : (!fir.heap<!fir.array<3x2xf32>>) -> !fir.ref<!fir.array<3x2xf32>>
-! CHECK:         fir.call @_QPbar_transpose_test(%[[VAL_24]]) {{.*}}: (!fir.ref<!fir.array<3x2xf32>>) -> ()
-! CHECK:         fir.freemem %[[VAL_7]] : !fir.heap<!fir.array<3x2xf32>>
-
+! CHECK: hlfir.declare %[[VAL_0]](%{{.*}}) {{.*}}{uniq_name = "_QFtranspose_testEmat"}
+! CHECK: hlfir.transpose {{.*}} : (!fir.ref<!fir.array<2x3xf32>>) -> !hlfir.expr<3x2xf32>
+! CHECK: fir.call @_QPbar_transpose_test
 ! CHECK-NOT: @_FortranATranspose
 end subroutine
 
 ! CHECK-LABEL: func.func @_QPtranspose_allocatable_test(
-! CHECK-SAME:                                           %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "mat"}) {
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>{{.*}})
 subroutine transpose_allocatable_test(mat)
   real, allocatable :: mat(:,:)
   mat = transpose(mat)
-! Verify that the "optimized" TRANSPOSE loops are generated
-! three times in each branch checking the status of LHS allocatable.
-
-! CHECK:         %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
-! CHECK:         %[[VAL_6:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !fir.heap<!fir.array<?x?xf32>>
-! CHECK:         %[[VAL_8:.*]] = fir.array_load %[[VAL_6]](%{{.*}}) : (!fir.heap<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
-
-! CHECK:         %[[VAL_9:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
-! CHECK:         %[[VAL_10:.*]] = fir.box_addr %[[VAL_9]] : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !fir.heap<!fir.array<?x?xf32>>
-
-! CHECK:         %[[VAL_14:.*]]:2 = fir.if %{{.*}} -> (i1, !fir.heap<!fir.array<?x?xf32>>) {
-
-! CHECK:           %[[VAL_24:.*]] = fir.if %{{.*}} -> (!fir.heap<!fir.array<?x?xf32>>) {
-
-! CHECK:             %[[VAL_25:.*]] = fir.allocmem !fir.array<?x?xf32>
-! CHECK:             %[[VAL_27:.*]] = fir.array_load %[[VAL_25]](%{{.*}}) : (!fir.heap<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
-
-! CHECK:             %[[VAL_32:.*]] = fir.do_loop %[[VAL_33:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_34:.*]] = %[[VAL_27]]) -> (!fir.array<?x?xf32>) {
-! CHECK:               %[[VAL_35:.*]] = fir.do_loop %[[VAL_36:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_37:.*]] = %[[VAL_34]]) -> (!fir.array<?x?xf32>) {
-! CHECK:                 %[[VAL_38:.*]] = fir.array_fetch %[[VAL_8]], %[[VAL_33]], %[[VAL_36]] : (!fir.array<?x?xf32>, index, index) -> f32
-! CHECK:                 %[[VAL_39:.*]] = fir.array_update %[[VAL_37]], %[[VAL_38]], %[[VAL_36]], %[[VAL_33]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
-! CHECK:                 fir.result %[[VAL_39]] : !fir.array<?x?xf32>
-! CHECK:               }
-! CHECK:               fir.result %[[VAL_35]] : !fir.array<?x?xf32>
-! CHECK:             }
-! CHECK:             fir.array_merge_store %[[VAL_27]], %[[VAL_32]] to %[[VAL_25]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.heap<!fir.array<?x?xf32>>
-
-! CHECK:           } else {
-
-! CHECK:             %[[VAL_43:.*]] = fir.array_load %[[VAL_10]](%{{.*}}) : (!fir.heap<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
-
-! CHECK:             %[[VAL_48:.*]] = fir.do_loop %[[VAL_49:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_50:.*]] = %[[VAL_43]]) -> (!fir.array<?x?xf32>) {
-! CHECK:               %[[VAL_51:.*]] = fir.do_loop %[[VAL_52:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_53:.*]] = %[[VAL_50]]) -> (!fir.array<?x?xf32>) {
-! CHECK:                 %[[VAL_54:.*]] = fir.array_fetch %[[VAL_8]], %[[VAL_49]], %[[VAL_52]] : (!fir.array<?x?xf32>, index, index) -> f32
-! CHECK:                 %[[VAL_55:.*]] = fir.array_update %[[VAL_53]], %[[VAL_54]], %[[VAL_52]], %[[VAL_49]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
-! CHECK:                 fir.result %[[VAL_55]] : !fir.array<?x?xf32>
-! CHECK:               }
-! CHECK:               fir.result %[[VAL_51]] : !fir.array<?x?xf32>
-! CHECK:             }
-! CHECK:             fir.array_merge_store %[[VAL_43]], %[[VAL_48]] to %[[VAL_10]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.heap<!fir.array<?x?xf32>>
-
-! CHECK:             fir.result %[[VAL_10]] : !fir.heap<!fir.array<?x?xf32>>
-! CHECK:           }
-
-! CHECK:         } else {
-
-! CHECK:           %[[VAL_60:.*]] = fir.allocmem !fir.array<?x?xf32>
-! CHECK:           %[[VAL_62:.*]] = fir.array_load %[[VAL_60]](%{{.*}}) : (!fir.heap<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
-
-! CHECK:           %[[VAL_67:.*]] = fir.do_loop %[[VAL_68:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_69:.*]] = %[[VAL_62]]) -> (!fir.array<?x?xf32>) {
-! CHECK:             %[[VAL_70:.*]] = fir.do_loop %[[VAL_71:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_72:.*]] = %[[VAL_69]]) -> (!fir.array<?x?xf32>) {
-! CHECK:               %[[VAL_73:.*]] = fir.array_fetch %[[VAL_8]], %[[VAL_68]], %[[VAL_71]] : (!fir.array<?x?xf32>, index, index) -> f32
-! CHECK:               %[[VAL_74:.*]] = fir.array_update %[[VAL_72]], %[[VAL_73]], %[[VAL_71]], %[[VAL_68]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
-! CHECK:               fir.result %[[VAL_74]] : !fir.array<?x?xf32>
-! CHECK:             }
-! CHECK:             fir.result %[[VAL_70]] : !fir.array<?x?xf32>
-! CHECK:           }
-! CHECK:           fir.array_merge_store %[[VAL_62]], %[[VAL_67]] to %[[VAL_60]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.heap<!fir.array<?x?xf32>>
-
-! CHECK:         }
-
+! Verify that hlfir.transpose is used (not explicit loops or runtime call)
+! CHECK: hlfir.declare %[[VAL_0]] {{.*}}{fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtranspose_allocatable_testEmat"}
+! CHECK: hlfir.transpose {{.*}} : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !hlfir.expr<?x?xf32>
+! CHECK: hlfir.assign {{.*}} realloc
+! CHECK: hlfir.destroy {{.*}} : !hlfir.expr<?x?xf32>
 ! CHECK-NOT: @_FortranATranspose
 end subroutine
diff --git a/flang/test/Lower/Intrinsics/trim.f90 b/flang/test/Lower/Intrinsics/trim.f90
index c88e07f2a4e25..1e62711d7e0b9 100644
--- a/flang/test/Lower/Intrinsics/trim.f90
+++ b/flang/test/Lower/Intrinsics/trim.f90
@@ -1,21 +1,17 @@
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 ! CHECK-LABEL: func @_QPtrim_test(
-! CHECK-SAME: %[[arg0:.*]]: !fir.boxchar<1>{{.*}}) {
+! CHECK-SAME: %[[arg0:.*]]: !fir.boxchar<1>{{.*}})
 subroutine trim_test(c)
   character(*) :: c
-  ! CHECK: %[[tmpBox:.*]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>>
   ! CHECK-DAG: %[[c:.*]]:2 = fir.unboxchar %[[arg0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
-  ! CHECK-DAG: %[[cBox:.*]] = fir.embox %[[c]]#0 typeparams %[[c]]#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.box<!fir.char<1,?>>
-  ! CHECK-DAG: %[[cBoxNone:.*]] = fir.convert %[[cBox]] : (!fir.box<!fir.char<1,?>>) -> !fir.box<none>
-  ! CHECK-DAG: %[[resBox:.*]] = fir.convert %[[tmpBox]] : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> !fir.ref<!fir.box<none>>
-  ! CHECK: fir.call @{{.*}}Trim(%[[resBox]], %[[cBoxNone]], {{.*}}) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> ()
-  ! CHECK-DAG: %[[tmpAddr:.*]] = fir.box_addr
-  ! CHECK-DAG: fir.box_elesize
-  ! CHECK: fir.call @{{.*}}bar_trim_test
+  ! CHECK-DAG: %[[cDecl:.*]]:2 = hlfir.declare %[[c]]#0 typeparams %[[c]]#1 {{.*}}{uniq_name = "_QFtrim_testEc"}
+  ! CHECK: %[[trimmed:.*]] = hlfir.char_trim %[[cDecl]]#0 : (!fir.boxchar<1>) -> !hlfir.expr<!fir.char<1,?>>
+  ! CHECK: %[[trimLen:.*]] = hlfir.get_length %[[trimmed]] : (!hlfir.expr<!fir.char<1,?>>) -> index
+  ! CHECK: %[[assoc:.*]]:3 = hlfir.associate %[[trimmed]] typeparams %[[trimLen]] {adapt.valuebyref}
+  ! CHECK: fir.call @{{.*}}bar_trim_test(%[[assoc]]#0)
+  ! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2
+  ! CHECK: hlfir.destroy %[[trimmed]] : !hlfir.expr<!fir.char<1,?>>
   call bar_trim_test(trim(c))
-  ! CHECK: fir.freemem %[[tmpAddr]] : !fir.heap<!fir.char<1,?>>
   return
 end subroutine
-
diff --git a/flang/test/Lower/Intrinsics/ubound.f90 b/flang/test/Lower/Intrinsics/ubound.f90
index bc8cff8982542..7648f1538bc69 100644
--- a/flang/test/Lower/Intrinsics/ubound.f90
+++ b/flang/test/Lower/Intrinsics/ubound.f90
@@ -1,25 +1,18 @@
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %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<none>, i32, !fir.ref<i8>, i32) -> i64
-! CHECK:         %[[VAL_6:.*]] = fir.address_of(
-! CHECK:         %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
-! 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<none>, i32, !fir.ref<i8>, 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<i64>
+! CHECK-DAG: %[[aDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_testEa"}
+! CHECK-DAG: %[[dimDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_testEdim"}
+! CHECK-DAG: %[[resDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_testEres"}
+! CHECK: %[[dimVal:.*]] = fir.load %[[dimDecl]]#0 : !fir.ref<i64>
+! CHECK: %[[size:.*]] = fir.call @_FortranASizeDim({{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
+! CHECK: %[[lbound:.*]] = fir.call @_FortranALboundDim({{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
+! CHECK: %[[lb_m1:.*]] = arith.subi %[[lbound]], {{.*}} : i64
+! CHECK: %[[ub:.*]] = arith.addi %[[lb_m1]], %[[size]] : i64
+! CHECK: hlfir.assign %[[ub]] to %[[resDecl]]#0 : i64, !fir.ref<i64>
   res = ubound(a, dim, 8)
 end subroutine
 
@@ -27,20 +20,14 @@ subroutine ubound_test(a, dim, res)
 subroutine ubound_test_2(a, dim, res)
   real, dimension(2:, 3:) :: a
   integer(8):: dim, res
-! CHECK:         %[[VAL_0:.*]] = fir.load %{{.*}} : !fir.ref<i64>
-! CHECK:         %[[VAL_1:.*]] = fir.address_of(
-! CHECK:         %[[VAL_2:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
-! 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<none>, i32, !fir.ref<i8>, i32) -> i64
-! CHECK:         %[[VAL_6:.*]] = fir.address_of(
-! CHECK:         %[[VAL_7:.*]] = fir.convert %{{.*}} : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>
-! 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<none>, i32, !fir.ref<i8>, 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<i64>
+! CHECK-DAG: %[[aDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_test_2Ea"}
+! CHECK-DAG: %[[dimDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_test_2Edim"}
+! CHECK-DAG: %[[resDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFubound_test_2Eres"}
+! CHECK: %[[size:.*]] = fir.call @_FortranASizeDim({{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
+! CHECK: %[[lbound:.*]] = fir.call @_FortranALboundDim({{.*}}) {{.*}}: (!fir.box<none>, i32, !fir.ref<i8>, i32) -> i64
+! CHECK: %[[lb_m1:.*]] = arith.subi %[[lbound]], {{.*}} : i64
+! CHECK: %[[ub:.*]] = arith.addi %[[lb_m1]], %[[size]] : i64
+! CHECK: hlfir.assign %[[ub]] to %[[resDecl]]#0 : i64, !fir.ref<i64>
   res = ubound(a, dim, 8)
 end subroutine
 
@@ -48,25 +35,15 @@ subroutine ubound_test_2(a, dim, res)
 subroutine ubound_test_3(a, dim, res)
   real, dimension(10, 20, *) :: a
   integer(8):: dim, res
-! CHECK:         %[[VAL_0:.*]] = fir.assumed_size_extent : index
-! CHECK:         %[[VAL_1:.*]] = fir.shape %{{.*}}, %{{.*}}, %[[VAL_0]] : (index, index, index) -> !fir.shape<3>
-! CHECK:         %[[VAL_2:.*]] = fir.embox %{{.*}}(%[[VAL_1]]) : (!fir.ref<!fir.array<10x20x?xf32>>, !fir.shape<3>) -> !fir.box<!fir.array<10x20x?xf32>>
-! CHECK:         %[[VAL_3:.*]] = fir.load %{{.*}} : !fir.ref<i64>
-! CHECK:         %[[VAL_4:.*]] = fir.address_of(
-! CHECK:         %[[VAL_5:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<none>
-
-! 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<none>, i32, !fir.ref<i8>, i32) -> i64
-! CHECK:         %[[VAL_9:.*]] = fir.rebox %[[VAL_2]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<!fir.array<10x20x?xf32>>
-! CHECK:         %[[VAL_10:.*]] = fir.address_of(
-! CHECK:         %[[VAL_11:.*]] = fir.convert %[[VAL_9]] : (!fir.box<!fir.array<10x20x?xf32>>) -> !fir.box<none>
-! 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<none>, i32, !fir.ref<i8>, 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<i64>
+! CHECK: %[[assumed:.*]] = fir.assumed_size_extent : index
+! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, %{{.*}}, %[[assumed]] : (index, index, index) -> !fir.shape<3>
+! CHECK: %[[aDecl:.*]]:2 = hlfir.declare {{.*}}(%[[shape]]) {{.*}}{uniq_name = "_QFubound_test_3Ea"}
+! CHECK: %[[embox:.*]] = fir.embox %[[aDecl]]#1(%{{.*}}) : (!fi...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/191753


More information about the flang-commits mailing list