From 298404d2de82504f2ed13358781baed245abb1d3 Mon Sep 17 00:00:00 2001 From: Eugene Epshteyn Date: Mon, 30 Mar 2026 09:36:34 -0400 Subject: [PATCH] [flang][NFC] Converted five tests from old lowering to new lowering (part 39) (#188386) Tests converted from test/Lower/Intrinsics: product.f90, random.f90, real.f90, repeat.f90, reshape.f90 --- .../test/Lower/Intrinsics/product-kind-10.f90 | 23 +++++ flang/test/Lower/Intrinsics/product.f90 | 96 +++++++------------ flang/test/Lower/Intrinsics/random.f90 | 60 +++++------- flang/test/Lower/Intrinsics/real.f90 | 10 +- flang/test/Lower/Intrinsics/repeat.f90 | 14 ++- flang/test/Lower/Intrinsics/reshape.f90 | 84 +++++++--------- 6 files changed, 124 insertions(+), 163 deletions(-) create mode 100644 flang/test/Lower/Intrinsics/product-kind-10.f90 diff --git a/flang/test/Lower/Intrinsics/product-kind-10.f90 b/flang/test/Lower/Intrinsics/product-kind-10.f90 new file mode 100644 index 000000000000..5a98a0900f46 --- /dev/null +++ b/flang/test/Lower/Intrinsics/product-kind-10.f90 @@ -0,0 +1,23 @@ +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK%if target=x86_64{{.*}} %{,CHECK-KIND10%} + +! This test was extracted from product.f90, since most tests in product.f90 didn't +! need types specific to x86 platform. + +! Note: originally, the test used 'REQUIRES' directive for +! x86-registered-target' to try to avoid running on platforms that don't +! support kind 10. Unfortunately, this checks if the x86 backend was compiled +! into LLVM, not whether the host is x86. On ARM CI machines with multi-target +! LLVM builds, this feature is set to true, so the test runs. With +! COMPLEX(KIND=10) (f80) not unsupported on ARM, this caused a semantic error. +! For this reason, change this test to support CHECK-KIND10 mechanism. (The +! same mechanism is used by nearest.f90 and sum.f90 tests.) + +! CHECK-LABEL: func @_QPproduct_test4( +! CHECK-KIND10-SAME: %[[arg0:.*]]: !fir.box>>{{.*}}) -> complex +function product_test4(x) + integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10) + complex(kind10) :: product_test4 + complex(kind10):: x(:) + product_test4 = product(x) +! CHECK-KIND10: hlfir.product {{.*}} : (!fir.box>>) -> complex +end function diff --git a/flang/test/Lower/Intrinsics/product.f90 b/flang/test/Lower/Intrinsics/product.f90 index c64982e435f0..88443cfeea29 100644 --- a/flang/test/Lower/Intrinsics/product.f90 +++ b/flang/test/Lower/Intrinsics/product.f90 @@ -1,17 +1,12 @@ -! REQUIRES: x86-registered-target -! RUN: bbc -target x86_64-unknown-linux-gnu --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! CHECK-LABEL: func @_QPproduct_test( ! CHECK-SAME: %[[arg0:.*]]: !fir.box>{{.*}}) -> i32 integer function product_test(a) integer :: a(:) -! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index -! CHECK-DAG: %[[a1:.*]] = fir.absent !fir.box -! CHECK-DAG: %[[a3:.*]] = fir.convert %[[arg0]] : (!fir.box>) -> !fir.box -! CHECK-DAG: %[[a5:.*]] = fir.convert %[[c0]] : (index) -> i32 -! CHECK-DAG: %[[a6:.*]] = fir.convert %[[a1]] : (!fir.box) -> !fir.box +! CHECK: hlfir.declare %[[arg0]] product_test = product(a) -! CHECK: %{{.*}} = fir.call @_FortranAProductInteger4(%[[a3]], %{{.*}}, %{{.*}}, %[[a5]], %[[a6]]) {{.*}}: (!fir.box, !fir.ref, i32, i32, !fir.box) -> i32 +! CHECK: hlfir.product {{.*}} : (!fir.box>) -> i32 end function ! CHECK-LABEL: func @_QPproduct_test2( @@ -19,55 +14,33 @@ end function subroutine product_test2(a,r) integer :: a(:,:) integer :: r(:) -! CHECK-DAG: %[[c2_i32:.*]] = arith.constant 2 : i32 -! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box>> -! CHECK-DAG: %[[a1:.*]] = fir.absent !fir.box -! CHECK-DAG: %[[a6:.*]] = fir.convert %[[a0]] : (!fir.ref>>>) -> !fir.ref> -! CHECK-DAG: %[[a7:.*]] = fir.convert %[[arg0]] : (!fir.box>) -> !fir.box -! CHECK-DAG: %[[a9:.*]] = fir.convert %[[a1]] : (!fir.box) -> !fir.box +! CHECK-DAG: %[[c2_i32:.*]] = arith.constant 2 : i32 +! CHECK-DAG: %[[aDecl:.*]]:2 = hlfir.declare %[[arg0]] +! CHECK-DAG: %[[rDecl:.*]]:2 = hlfir.declare %[[arg1]] r = product(a,dim=2) -! CHECK: fir.call @_FortranAProductDim(%[[a6]], %[[a7]], %[[c2_i32]], %{{.*}}, %{{.*}}, %[[a9]]) {{.*}}: (!fir.ref>, !fir.box, i32, !fir.ref, i32, !fir.box) -> () -! CHECK-DAG: %[[a11:.*]] = fir.load %[[a0]] : !fir.ref>>> -! CHECK-DAG: %[[a13:.*]] = fir.box_addr %[[a11]] : (!fir.box>>) -> !fir.heap> -! CHECK-DAG: fir.freemem %[[a13]] +! CHECK: hlfir.product %[[aDecl]]#0 dim %[[c2_i32]] {{.*}} : (!fir.box>, i32) -> !hlfir.expr end subroutine ! CHECK-LABEL: func @_QPproduct_test3( ! CHECK-SAME: %[[arg0:.*]]: !fir.box>>{{.*}}) -> complex complex function product_test3(a) complex :: a(:) -! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index -! CHECK-DAG: %[[a0:.*]] = fir.alloca complex -! CHECK-DAG: %[[a3:.*]] = fir.absent !fir.box -! CHECK-DAG: %[[a6:.*]] = fir.convert %[[arg0]] : (!fir.box>>) -> !fir.box -! CHECK-DAG: %[[a8:.*]] = fir.convert %[[c0]] : (index) -> i32 -! CHECK-DAG: %[[a9:.*]] = fir.convert %[[a3]] : (!fir.box) -> !fir.box product_test3 = product(a) -! CHECK: fir.call @_FortranACppProductComplex4(%[[a0]], %[[a6]], %{{.*}}, %{{.*}}, %[[a8]], %[[a9]]) {{.*}}: (!fir.ref>, !fir.box, !fir.ref, i32, i32, !fir.box) -> () +! CHECK: hlfir.product {{.*}} : (!fir.box>>) -> complex end function -! CHECK-LABEL: func @_QPproduct_test4( -! CHECK-SAME: %[[arg0:.*]]: !fir.box>>{{.*}}) -> complex -complex(10) function product_test4(x) -complex(10):: x(:) -! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index -! CHECK-DAG: %[[a0:.*]] = fir.alloca complex -product_test4 = product(x) -! CHECK-DAG: %[[a2:.*]] = fir.absent !fir.box -! CHECK-DAG: %[[a5:.*]] = fir.convert %[[arg0]] : (!fir.box>>) -> !fir.box -! CHECK-DAG: %[[a7:.*]] = fir.convert %[[c0]] : (index) -> i32 -! CHECK-DAG: %[[a8:.*]] = fir.convert %[[a2]] : (!fir.box) -> !fir.box -! CHECK: fir.call @_FortranACppProductComplex10(%[[a0]], %[[a5]], %{{.*}}, %{{.*}}, %[[a7]], %{{[0-9]+}}) {{.*}}: (!fir.ref>, !fir.box, !fir.ref, i32, i32, !fir.box) -> () -end - ! CHECK-LABEL: func @_QPproduct_test_optional( ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box>> real function product_test_optional(mask, x) real :: x(:) logical, optional :: mask(:) product_test_optional = product(x, mask=mask) -! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_0]] : (!fir.box>>) -> !fir.box -! CHECK: fir.call @_FortranAProductReal4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_9]]) {{.*}}: (!fir.box, !fir.ref, i32, i32, !fir.box) -> f32 +! CHECK-DAG: %[[maskDecl:.*]]:2 = hlfir.declare %[[VAL_0]] {{.*}}optional +! CHECK-DAG: %[[xDecl:.*]]:2 = hlfir.declare %{{.*}} {{.*}}{uniq_name = "_QFproduct_test_optionalEx"} +! CHECK: %[[isPresent:.*]] = fir.is_present %[[maskDecl]]#0 +! CHECK: %[[absent:.*]] = fir.absent !fir.box>> +! CHECK: %[[opt:.*]] = arith.select %[[isPresent]], %[[maskDecl]]#1, %[[absent]] +! CHECK: hlfir.product %[[xDecl]]#0 mask %[[opt]] {{.*}} : (!fir.box>, !fir.box>>) -> f32 end function ! CHECK-LABEL: func @_QPproduct_test_optional_2( @@ -76,16 +49,16 @@ real function product_test_optional_2(mask, x) real :: x(:) logical, pointer :: mask(:) product_test_optional = product(x, mask=mask) -! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_0]] : !fir.ref>>>> +! CHECK: %[[maskDecl:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK: %[[VAL_4:.*]] = fir.load %[[maskDecl]]#0 : !fir.ref>>>> ! CHECK: %[[VAL_5:.*]] = fir.box_addr %[[VAL_4]] : (!fir.box>>>) -> !fir.ptr>> ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.ptr>>) -> i64 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64 -! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_0]] : !fir.ref>>>> +! CHECK: %[[VAL_9:.*]] = fir.load %[[maskDecl]]#0 : !fir.ref>>>> ! CHECK: %[[VAL_10:.*]] = fir.absent !fir.box>>> ! CHECK: %[[VAL_11:.*]] = arith.select %[[VAL_8]], %[[VAL_9]], %[[VAL_10]] : !fir.box>>> -! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_11]] : (!fir.box>>>) -> !fir.box -! CHECK: fir.call @_FortranAProductReal4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_18]]) {{.*}}: (!fir.box, !fir.ref, i32, i32, !fir.box) -> f32 +! CHECK: hlfir.product {{.*}} mask %[[VAL_11]] {{.*}} : (!fir.box>, !fir.box>>>) -> f32 end function ! CHECK-LABEL: func @_QPproduct_test_optional_3( @@ -94,14 +67,13 @@ real function product_test_optional_3(mask, x) real :: x(:) logical, optional :: mask(10) product_test_optional = product(x, mask=mask) -! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index -! CHECK: %[[VAL_5:.*]] = fir.is_present %[[VAL_0]] : (!fir.ref>>) -> i1 -! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> -! CHECK: %[[VAL_7:.*]] = fir.embox %[[VAL_0]](%[[VAL_6]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> +! CHECK: %[[maskDecl:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK: %[[VAL_5:.*]] = fir.is_present %[[maskDecl]]#0 : (!fir.ref>>) -> i1 +! CHECK: %[[VAL_6:.*]] = fir.shape +! CHECK: %[[VAL_7:.*]] = fir.embox %[[maskDecl]]#0(%[[VAL_6]]) ! CHECK: %[[VAL_8:.*]] = fir.absent !fir.box>> ! CHECK: %[[VAL_9:.*]] = arith.select %[[VAL_5]], %[[VAL_7]], %[[VAL_8]] : !fir.box>> -! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_9]] : (!fir.box>>) -> !fir.box -! CHECK: fir.call @_FortranAProductReal4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_18]]) {{.*}}: (!fir.box, !fir.ref, i32, i32, !fir.box) -> f32 +! CHECK: hlfir.product {{.*}} mask %[[VAL_9]] {{.*}} : (!fir.box>, !fir.box>>) -> f32 end function ! CHECK-LABEL: func @_QPproduct_test_optional_4( @@ -117,17 +89,13 @@ if (use_mask) then ! CHECK: fir.call @_QPset_mask end if product_test_optional = product(x, mask=mask) -! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_3:.*]] : !fir.ref>>> -! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (!fir.heap>>) -> i64 -! CHECK: %[[VAL_22:.*]] = arith.constant 0 : i64 -! CHECK: %[[VAL_23:.*]] = arith.cmpi ne, %[[VAL_21]], %[[VAL_22]] : i64 -! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_4:.*]] : !fir.ref -! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_5:.*]] : !fir.ref -! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_3]] : !fir.ref>>> -! CHECK: %[[VAL_27:.*]] = fir.shape_shift %[[VAL_24]], %[[VAL_25]] : (index, index) -> !fir.shapeshift<1> -! CHECK: %[[VAL_28:.*]] = fir.embox %[[VAL_26]](%[[VAL_27]]) : (!fir.heap>>, !fir.shapeshift<1>) -> !fir.box>> -! CHECK: %[[VAL_29:.*]] = fir.absent !fir.box>> -! CHECK: %[[VAL_30:.*]] = arith.select %[[VAL_23]], %[[VAL_28]], %[[VAL_29]] : !fir.box>> -! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_30]] : (!fir.box>>) -> !fir.box -! CHECK: fir.call @_FortranAProductReal4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_37]]) {{.*}}: (!fir.box, !fir.ref, i32, i32, !fir.box) -> f32 +! CHECK: %[[VAL_20:.*]] = fir.load %[[maskBox:.*]] : !fir.ref>>>> +! CHECK: %[[VAL_21:.*]] = fir.box_addr %[[VAL_20]] : (!fir.box>>>) -> !fir.heap>> +! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (!fir.heap>>) -> i64 +! CHECK: %[[VAL_23:.*]] = arith.constant 0 : i64 +! CHECK: %[[VAL_24:.*]] = arith.cmpi ne, %[[VAL_22]], %[[VAL_23]] : i64 +! CHECK: %[[VAL_25:.*]] = fir.load %[[maskBox]] : !fir.ref>>>> +! CHECK: %[[VAL_26:.*]] = fir.absent !fir.box>>> +! CHECK: %[[VAL_27:.*]] = arith.select %[[VAL_24]], %[[VAL_25]], %[[VAL_26]] : !fir.box>>> +! CHECK: hlfir.product {{.*}} mask %[[VAL_27]] {{.*}} : (!fir.box>, !fir.box>>>) -> f32 end function diff --git a/flang/test/Lower/Intrinsics/random.f90 b/flang/test/Lower/Intrinsics/random.f90 index 5f7d6414e606..fe5d6b319da2 100644 --- a/flang/test/Lower/Intrinsics/random.f90 +++ b/flang/test/Lower/Intrinsics/random.f90 @@ -1,40 +1,30 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! CHECK-LABEL: func @_QPrandom_test_1 subroutine random_test_1 - ! CHECK-DAG: [[ss:%[0-9]+]] = fir.alloca {{.*}}random_test_1Ess - ! CHECK-DAG: [[vv:%[0-9]+]] = fir.alloca {{.*}}random_test_1Evv + ! CHECK-DAG: hlfir.declare {{.*}}random_test_1Ess + ! CHECK-DAG: hlfir.declare {{.*}}random_test_1Evv integer ss, vv(40) - ! CHECK-DAG: [[rr:%[0-9]+]] = fir.alloca {{.*}}random_test_1Err - ! CHECK-DAG: [[aa:%[0-9]+]] = fir.alloca {{.*}}random_test_1Eaa + ! CHECK-DAG: hlfir.declare {{.*}}random_test_1Err + ! CHECK-DAG: hlfir.declare {{.*}}random_test_1Eaa real rr, aa(5) ! CHECK: fir.call @_FortranARandomInit(%true{{.*}}, %false{{.*}}) {{.*}}: (i1, i1) -> () call random_init(.true., .false.) - ! CHECK: [[box:%[0-9]+]] = fir.embox [[ss]] - ! CHECK: [[argbox:%[0-9]+]] = fir.convert [[box]] - ! CHECK: fir.call @_FortranARandomSeedSize([[argbox]] + ! CHECK: fir.call @_FortranARandomSeedSize( call random_seed(size=ss) print*, 'size: ', ss ! CHECK: fir.call @_FortranARandomSeedDefaultPut() {{.*}}: () -> () call random_seed() - ! CHECK: [[box:%[0-9]+]] = fir.embox [[rr]] - ! CHECK: [[argbox:%[0-9]+]] = fir.convert [[box]] - ! CHECK: fir.call @_FortranARandomNumber([[argbox]] + ! CHECK: fir.call @_FortranARandomNumber( call random_number(rr) print*, rr - ! CHECK: [[box:%[0-9]+]] = fir.embox [[vv]] - ! CHECK: [[argbox:%[0-9]+]] = fir.convert [[box]] - ! CHECK: fir.call @_FortranARandomSeedGet([[argbox]] + ! CHECK: fir.call @_FortranARandomSeedGet( call random_seed(get=vv) ! print*, 'get: ', vv(1:ss) - ! CHECK: [[box:%[0-9]+]] = fir.embox [[vv]] - ! CHECK: [[argbox:%[0-9]+]] = fir.convert [[box]] - ! CHECK: fir.call @_FortranARandomSeedPut([[argbox]] + ! CHECK: fir.call @_FortranARandomSeedPut( call random_seed(put=vv) print*, 'put: ', vv(1:ss) - ! CHECK: [[box:%[0-9]+]] = fir.embox [[aa]] - ! CHECK: [[argbox:%[0-9]+]] = fir.convert [[box]] - ! CHECK: fir.call @_FortranARandomNumber([[argbox]] + ! CHECK: fir.call @_FortranARandomNumber( call random_number(aa) print*, aa end @@ -47,21 +37,21 @@ subroutine random_test_2 contains ! CHECK-LABEL: func private @_QFrandom_test_2Pfoo subroutine foo(size, put, get) - ! CHECK: [[s1:%[0-9]+]] = fir.is_present %arg0 - ! CHECK: [[s2:%[0-9]+]] = fir.embox %arg0 + integer, optional :: size + integer, optional :: put(5) + integer, optional :: get(5) + ! CHECK: [[s1:%[0-9]+]] = fir.is_present + ! CHECK: [[p1:%[0-9]+]] = fir.is_present + ! CHECK: [[g1:%[0-9]+]] = fir.is_present + ! CHECK: [[s2:%[0-9]+]] = fir.embox ! CHECK: [[s3:%[0-9]+]] = fir.absent !fir.box ! CHECK: [[s4:%[0-9]+]] = arith.select [[s1]], [[s2]], [[s3]] : !fir.box - integer, optional :: size - ! CHECK: [[p1:%[0-9]+]] = fir.is_present %arg1 - ! CHECK: [[p2:%[0-9]+]] = fir.embox %arg1 + ! CHECK: [[p2:%[0-9]+]] = fir.embox ! CHECK: [[p3:%[0-9]+]] = fir.absent !fir.box> ! CHECK: [[p4:%[0-9]+]] = arith.select [[p1]], [[p2]], [[p3]] : !fir.box> - integer, optional :: put(5) - ! CHECK: [[g1:%[0-9]+]] = fir.is_present %arg2 - ! CHECK: [[g2:%[0-9]+]] = fir.embox %arg2 + ! CHECK: [[g2:%[0-9]+]] = fir.embox ! CHECK: [[g3:%[0-9]+]] = fir.absent !fir.box> ! CHECK: [[g4:%[0-9]+]] = arith.select [[g1]], [[g2]], [[g3]] : !fir.box> - integer, optional :: get(5) ! CHECK: [[s5:%[0-9]+]] = fir.convert [[s4]] : (!fir.box) -> !fir.box ! CHECK: [[p5:%[0-9]+]] = fir.convert [[p4]] : (!fir.box>) -> !fir.box ! CHECK: [[g5:%[0-9]+]] = fir.convert [[g4]] : (!fir.box>) -> !fir.box @@ -73,16 +63,16 @@ contains ! CHECK-LABEL: func private @_QFrandom_test_2Pbar subroutine bar(size, get, put) integer, optional :: size - ! CHECK: [[p1:%[0-9]+]] = fir.is_present %arg2 - ! CHECK: [[p2:%[0-9]+]] = fir.embox %arg2 + integer, optional :: put(5) + integer, optional :: get(5) + ! CHECK: [[p1:%[0-9]+]] = fir.is_present + ! CHECK: [[g1:%[0-9]+]] = fir.is_present + ! CHECK: [[p2:%[0-9]+]] = fir.embox ! CHECK: [[p3:%[0-9]+]] = fir.absent !fir.box> ! CHECK: [[p4:%[0-9]+]] = arith.select [[p1]], [[p2]], [[p3]] : !fir.box> - integer, optional :: put(5) - ! CHECK: [[g1:%[0-9]+]] = fir.is_present %arg1 - ! CHECK: [[g2:%[0-9]+]] = fir.embox %arg1 + ! CHECK: [[g2:%[0-9]+]] = fir.embox ! CHECK: [[g3:%[0-9]+]] = fir.absent !fir.box> ! CHECK: [[g4:%[0-9]+]] = arith.select [[g1]], [[g2]], [[g3]] : !fir.box> - integer, optional :: get(5) ! CHECK: [[s1:%[0-9]+]] = fir.absent !fir.box ! CHECK: [[p5:%[0-9]+]] = fir.convert [[p4]] : (!fir.box>) -> !fir.box ! CHECK: [[g5:%[0-9]+]] = fir.convert [[g4]] : (!fir.box>) -> !fir.box diff --git a/flang/test/Lower/Intrinsics/real.f90 b/flang/test/Lower/Intrinsics/real.f90 index f1f728e1a203..b822d43cf1a7 100644 --- a/flang/test/Lower/Intrinsics/real.f90 +++ b/flang/test/Lower/Intrinsics/real.f90 @@ -1,4 +1,4 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! Tests REAL lowering subroutine test_real() @@ -12,9 +12,11 @@ end subroutine ! CHECK-LABEL: func @_QPtest_real() { ! CHECK: %[[VAL_0:.*]] = fir.alloca f32 {bindc_name = "r4", uniq_name = "_QFtest_realEr4"} -! CHECK: %[[VAL_1:.*]] = fir.alloca f64 {bindc_name = "r8", uniq_name = "_QFtest_realEr8"} +! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_realEr4"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: %[[VAL_2:.*]] = fir.alloca f64 {bindc_name = "r8", uniq_name = "_QFtest_realEr8"} +! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFtest_realEr8"} : (!fir.ref) -> (!fir.ref, !fir.ref) ! CHECK: %[[CST_0:.*]] = arith.constant 8.968310e-44 : f32 -! CHECK: fir.store %[[CST_0]] to %[[VAL_0]] : !fir.ref +! CHECK: hlfir.assign %[[CST_0]] to %[[VAL_1]]#0 : f32, !fir.ref ! CHECK: %[[CST_1:.*]] = arith.constant 3.162020e-322 : f64 -! CHECK: fir.store %[[CST_1]] to %[[VAL_1]] : !fir.ref +! CHECK: hlfir.assign %[[CST_1]] to %[[VAL_3]]#0 : f64, !fir.ref ! CHECK: return diff --git a/flang/test/Lower/Intrinsics/repeat.f90 b/flang/test/Lower/Intrinsics/repeat.f90 index e95221405b66..c21b416942f4 100644 --- a/flang/test/Lower/Intrinsics/repeat.f90 +++ b/flang/test/Lower/Intrinsics/repeat.f90 @@ -1,24 +1,22 @@ -! 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 @_QPrepeat_test( ! CHECK-SAME: %[[arg0:.*]]: !fir.boxchar<1>{{.*}}, %[[arg1:.*]]: !fir.ref{{.*}}) { subroutine repeat_test(c, n) character(*) :: c integer :: n - ! CHECK: %[[tmpBox:.*]] = fir.alloca !fir.box>> + ! CHECK-DAG: %[[tmpBox:.*]] = fir.alloca !fir.box>> ! CHECK-DAG: %[[c:.*]]:2 = fir.unboxchar %[[arg0]] : (!fir.boxchar<1>) -> (!fir.ref>, index) - ! CHECK-DAG: %[[ni32:.*]] = fir.load %[[arg1]] : !fir.ref + ! CHECK-DAG: %[[cDecl:.*]]:2 = hlfir.declare %[[c]]#0 typeparams %[[c]]#1 + ! CHECK-DAG: %[[nDecl:.*]]:2 = hlfir.declare %[[arg1]] + ! CHECK-DAG: %[[ni32:.*]] = fir.load %[[nDecl]]#0 : !fir.ref ! CHECK-DAG: %[[n:.*]] = fir.convert %[[ni32]] : (i32) -> i64 - ! CHECK-DAG: %[[cBox:.*]] = fir.embox %[[c]]#0 typeparams %[[c]]#1 : (!fir.ref>, index) -> !fir.box> + ! CHECK-DAG: %[[cBox:.*]] = fir.embox %[[cDecl]]#1 typeparams %[[c]]#1 : (!fir.ref>, index) -> !fir.box> ! CHECK-DAG: %[[cBoxNone:.*]] = fir.convert %[[cBox]] : (!fir.box>) -> !fir.box ! CHECK-DAG: %[[resBox:.*]] = fir.convert %[[tmpBox]] : (!fir.ref>>>) -> !fir.ref> ! CHECK: fir.call @{{.*}}Repeat(%[[resBox]], %[[cBoxNone]], %[[n]], {{.*}}, {{.*}}) {{.*}}: (!fir.ref>, !fir.box, i64, !fir.ref, i32) -> () - ! CHECK-DAG: %[[tmpAddr:.*]] = fir.box_addr - ! CHECK-DAG: fir.box_elesize ! CHECK: fir.call @{{.*}}bar_repeat_test call bar_repeat_test(repeat(c,n)) - ! CHECK: fir.freemem %[[tmpAddr]] : !fir.heap> return end subroutine diff --git a/flang/test/Lower/Intrinsics/reshape.f90 b/flang/test/Lower/Intrinsics/reshape.f90 index b960a3e38078..63a788c5eaa7 100644 --- a/flang/test/Lower/Intrinsics/reshape.f90 +++ b/flang/test/Lower/Intrinsics/reshape.f90 @@ -1,4 +1,4 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! CHECK-LABEL: func @_QPreshape_test( ! CHECK-SAME: %[[arg0:.*]]: !fir.box>{{.*}}, %[[arg1:[^:]+]]: !fir.box>{{.*}}, %[[arg2:[^:]+]]: !fir.box>{{.*}}, %[[arg3:.*]]: !fir.ref>{{.*}}, %[[arg4:.*]]: !fir.ref>{{.*}}) { @@ -8,21 +8,15 @@ subroutine reshape_test(x, source, pd, sh, ord) integer :: pd(:,:,:) integer :: sh(2) integer :: ord(2) - ! CHECK-DAG: %[[c2:.*]] = arith.constant 2 : index - ! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box>> - ! CHECK-DAG: %[[a1:.*]] = fir.shape %[[c2]] : (index) -> !fir.shape<1> - ! CHECK-DAG: %[[a2:.*]] = fir.embox %[[arg3]](%{{.*}}) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK-DAG: %[[a3:.*]] = fir.embox %[[arg4]](%{{.*}}) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK-DAG: %[[a8:.*]] = fir.convert %[[a0]] : (!fir.ref>>>) -> !fir.ref> - ! CHECK-DAG: %[[a9:.*]] = fir.convert %[[arg1]] : (!fir.box>) -> !fir.box - ! CHECK-DAG: %[[a10:.*]] = fir.convert %[[a2]] : (!fir.box>) -> !fir.box - ! CHECK-DAG: %[[a11:.*]] = fir.convert %[[arg2]] : (!fir.box>) -> !fir.box - ! CHECK-DAG: %[[a12:.*]] = fir.convert %[[a3]] : (!fir.box>) -> !fir.box + ! CHECK-DAG: %[[ordDecl:.*]]:2 = hlfir.declare %[[arg4]] + ! CHECK-DAG: %[[pdDecl:.*]]:2 = hlfir.declare %[[arg2]] + ! CHECK-DAG: %[[shDecl:.*]]:2 = hlfir.declare %[[arg3]] + ! CHECK-DAG: %[[srcDecl:.*]]:2 = hlfir.declare %[[arg1]] + ! CHECK-DAG: %[[xDecl:.*]]:2 = hlfir.declare %[[arg0]] + ! CHECK: %[[res:.*]] = hlfir.reshape %[[srcDecl]]#0 %[[shDecl]]#0 pad %[[pdDecl]]#0 order %[[ordDecl]]#0 + ! CHECK: hlfir.assign %[[res]] to %[[xDecl]]#0 + ! CHECK: hlfir.destroy %[[res]] x = reshape(source, sh, pd, ord) - ! CHECK: fir.call @_FortranAReshape(%[[a8]], %[[a9]], %[[a10]], %[[a11]], %[[a12]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> () - ! CHECK-DAG: %[[a15:.*]] = fir.load %[[a0]] : !fir.ref>>> - ! CHECK-DAG: %[[a18:.*]] = fir.box_addr %[[a15]] : (!fir.box>>) -> !fir.heap> - ! CHECK-DAG: fir.freemem %[[a18]] end subroutine ! CHECK-LABEL: func @_QPtest_reshape_optional( @@ -34,49 +28,35 @@ subroutine reshape_test(x, source, pd, sh, ord) real :: source(:, :, :) integer :: shape(4) print *, reshape(source=source, shape=shape, pad=pad, order=order) - ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_0]] : !fir.ref>>> - ! CHECK: %[[VAL_14:.*]] = fir.box_addr %[[VAL_13]] : (!fir.box>>) -> !fir.ptr> - ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (!fir.ptr>) -> i64 - ! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64 - ! CHECK: %[[VAL_17:.*]] = arith.cmpi ne, %[[VAL_15]], %[[VAL_16]] : i64 - ! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_0]] : !fir.ref>>> - ! CHECK: %[[VAL_19:.*]] = fir.absent !fir.box>> - ! CHECK: %[[VAL_20:.*]] = arith.select %[[VAL_17]], %[[VAL_18]], %[[VAL_19]] : !fir.box>> - ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_1]] : !fir.ref>>> - ! CHECK: %[[VAL_22:.*]] = fir.box_addr %[[VAL_21]] : (!fir.box>>) -> !fir.ptr> - ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (!fir.ptr>) -> i64 - ! CHECK: %[[VAL_24:.*]] = arith.constant 0 : i64 - ! CHECK: %[[VAL_25:.*]] = arith.cmpi ne, %[[VAL_23]], %[[VAL_24]] : i64 - ! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_1]] : !fir.ref>>> - ! CHECK: %[[VAL_27:.*]] = fir.absent !fir.box>> - ! CHECK: %[[VAL_28:.*]] = arith.select %[[VAL_25]], %[[VAL_26]], %[[VAL_27]] : !fir.box>> - ! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_20]] : (!fir.box>>) -> !fir.box - ! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_28]] : (!fir.box>>) -> !fir.box - ! CHECK: fir.call @_FortranAReshape({{.*}}, {{.*}}, %{{.*}}, %[[VAL_38]], %[[VAL_39]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> () + ! CHECK-DAG: %[[padDecl:.*]]:2 = hlfir.declare %[[VAL_0]] {{.*}}pad + ! CHECK-DAG: %[[orderDecl:.*]]:2 = hlfir.declare %[[VAL_1]] {{.*}}order + ! CHECK: %[[padLoad1:.*]] = fir.load %[[padDecl]]#0 : !fir.ref>>> + ! CHECK: %[[padAddr:.*]] = fir.box_addr %[[padLoad1]] : (!fir.box>>) -> !fir.ptr> + ! CHECK: %[[padI64:.*]] = fir.convert %[[padAddr]] : (!fir.ptr>) -> i64 + ! CHECK: %[[c0:.*]] = arith.constant 0 : i64 + ! CHECK: %[[padNonNull:.*]] = arith.cmpi ne, %[[padI64]], %[[c0]] : i64 + ! CHECK: %[[orderLoad1:.*]] = fir.load %[[orderDecl]]#0 : !fir.ref>>> + ! CHECK: %[[orderAddr:.*]] = fir.box_addr %[[orderLoad1]] : (!fir.box>>) -> !fir.ptr> + ! CHECK: %[[orderI64:.*]] = fir.convert %[[orderAddr]] : (!fir.ptr>) -> i64 + ! CHECK: %[[c0_2:.*]] = arith.constant 0 : i64 + ! CHECK: %[[orderNonNull:.*]] = arith.cmpi ne, %[[orderI64]], %[[c0_2]] : i64 + ! CHECK: %[[padLoad2:.*]] = fir.load %[[padDecl]]#0 : !fir.ref>>> + ! CHECK: %[[padAbsent:.*]] = fir.absent !fir.box>> + ! CHECK: %[[padOpt:.*]] = arith.select %[[padNonNull]], %[[padLoad2]], %[[padAbsent]] : !fir.box>> + ! CHECK: %[[orderLoad2:.*]] = fir.load %[[orderDecl]]#0 : !fir.ref>>> + ! CHECK: %[[orderAbsent:.*]] = fir.absent !fir.box>> + ! CHECK: %[[orderOpt:.*]] = arith.select %[[orderNonNull]], %[[orderLoad2]], %[[orderAbsent]] : !fir.box>> + ! CHECK: hlfir.reshape {{.*}} pad %[[padOpt]] order %[[orderOpt]] 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: fir.call @_FortranAReshape(%{{.*}}, %[[VAL_25]], %[[VAL_26]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> () subroutine test_reshape_shape_slice() integer, parameter :: i = 1 real :: tmp(4) = [1,2,3,4] integer :: dims(4) = [2,2,2,2] + ! CHECK: %[[dimsDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFtest_reshape_shape_sliceEdims"} + ! CHECK: %[[tmpDecl:.*]]:2 = hlfir.declare {{.*}}{uniq_name = "_QFtest_reshape_shape_sliceEtmp"} + ! CHECK: %[[sliceRef:.*]] = hlfir.designate %[[dimsDecl]]#0 ({{.*}}:{{.*}}:{{.*}}) + ! CHECK: hlfir.reshape %[[tmpDecl]]#0 %[[sliceRef]] call some_proc(reshape(tmp, dims(i:2))) end