[flang-commits] [flang] 1fb0707 - [flang][hlfir] Simplify hlfir::convertToValue

Jean Perier via flang-commits flang-commits at lists.llvm.org
Fri Jun 23 00:20:23 PDT 2023


Author: Jean Perier
Date: 2023-06-23T09:04:25+02:00
New Revision: 1fb0707da6e7c8a2a8981e52fb405a047c6df726

URL: https://github.com/llvm/llvm-project/commit/1fb0707da6e7c8a2a8981e52fb405a047c6df726
DIFF: https://github.com/llvm/llvm-project/commit/1fb0707da6e7c8a2a8981e52fb405a047c6df726.diff

LOG: [flang][hlfir] Simplify hlfir::convertToValue

Use hlfir::loadTrivialScalars to dereference pointer, allocatables, and
load numerical and logical scalars.

This has a small fallout on tests:

- load is done on the HLFIR entity (#0 of hlfir.declare) and not the FIR one (#1). This makes no difference at the FIR level (#1 and #0 only differs to account for assumed and explicit shape lower bounds).

- loadTrivialScalars get rids of allocatable fir.box for monomoprhic scalars
  (it is not needed). This exposed a bug in lowering of MERGE with
  a polymorphic and a monomorphic argument: when the monomorphic is not
  a fir.box, the polymorphic fir.class should not be reboxed but its
  address should be read.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D153252

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/HLFIRTools.cpp
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp
    flang/test/Lower/HLFIR/calls-character-singleton-result.f90
    flang/test/Lower/HLFIR/calls-f77.f90
    flang/test/Lower/HLFIR/convert-mbox-to-value.f90
    flang/test/Lower/HLFIR/expr-as-inquired.f90
    flang/test/Lower/HLFIR/expr-value.f90
    flang/test/Lower/HLFIR/forall.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
index a11c235510fe9..99a699b35d27a 100644
--- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp
+++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
@@ -912,52 +912,11 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
 std::pair<fir::ExtendedValue, std::optional<hlfir::CleanupFunction>>
 hlfir::convertToValue(mlir::Location loc, fir::FirOpBuilder &builder,
                       const hlfir::Entity &entity) {
-  auto [exv, cleanup] = translateToExtendedValue(loc, builder, entity);
   // Load scalar references to integer, logical, real, or complex value
   // to an mlir value, dereference allocatable and pointers, and get rid
   // of fir.box that are not needed or create a copy into contiguous memory.
-  exv = exv.match(
-      [&](const fir::UnboxedValue &box) -> fir::ExtendedValue {
-        if (mlir::Type elementType = fir::dyn_cast_ptrEleTy(box.getType()))
-          if (fir::isa_trivial(elementType))
-            return builder.create<fir::LoadOp>(loc, box);
-        return box;
-      },
-      [&](const fir::CharBoxValue &box) -> fir::ExtendedValue { return box; },
-      [&](const fir::ArrayBoxValue &box) -> fir::ExtendedValue { return box; },
-      [&](const fir::CharArrayBoxValue &box) -> fir::ExtendedValue {
-        return box;
-      },
-      [&](const fir::MutableBoxValue &box) -> fir::ExtendedValue {
-        if (box.rank() != 0)
-          TODO(loc, "lower array descriptor designator to HLFIR value");
-        if (entity.isProcedure())
-          TODO(loc, "lower proc descriptor designator to HLFIR value");
-
-        hlfir::Entity derefedEntity =
-            hlfir::derefPointersAndAllocatables(loc, builder, entity);
-        mlir::Type eleTy = derefedEntity.getFortranElementType();
-
-        // Trivial values are unboxed.
-        if (derefedEntity.isScalar() && fir::isa_trivial(eleTy))
-          return builder.create<fir::LoadOp>(loc, derefedEntity);
-
-        if (mlir::isa<fir::CharacterType>(eleTy)) {
-          if (mlir::isa<fir::BoxCharType>(derefedEntity.getFirBase().getType()))
-            return genUnboxChar(loc, builder, derefedEntity.getFirBase());
-          // Extract length from the original entity.
-          mlir::Value len = genCharacterVariableLength(loc, builder, entity);
-          return fir::CharBoxValue{derefedEntity, len};
-        }
-
-        // Keep derived type value boxed.
-        return fir::factory::genMutableBoxRead(builder, loc, box);
-      },
-      [&](const auto &) -> fir::ExtendedValue {
-        // Can we end up here?
-        TODO(loc, "lower descriptor designator to HLFIR value");
-      });
-  return {exv, cleanup};
+  auto derefedAndLoadedEntity = loadTrivialScalar(loc, builder, entity);
+  return translateToExtendedValue(loc, builder, derefedAndLoadedEntity);
 }
 
 static fir::ExtendedValue placeTrivialInMemory(mlir::Location loc,

diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index d5b266bb5702d..2f3722db85af8 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -3638,20 +3638,21 @@ IntrinsicLibrary::genMerge(mlir::Type,
   // used.
   mlir::Value tsourceCast = tsource;
   mlir::Value fsourceCast = fsource;
+  auto convertToStaticType = [&](mlir::Value polymorphic,
+                                 mlir::Value other) -> mlir::Value {
+    mlir::Type otherType = other.getType();
+    if (otherType.isa<fir::BaseBoxType>())
+      return builder.create<fir::ReboxOp>(loc, otherType, polymorphic,
+                                          /*shape*/ mlir::Value{},
+                                          /*slice=*/mlir::Value{});
+    return builder.create<fir::BoxAddrOp>(loc, otherType, polymorphic);
+  };
   if (fir::isPolymorphicType(tsource.getType()) &&
       !fir::isPolymorphicType(fsource.getType())) {
-    tsourceCast = builder.create<fir::ReboxOp>(loc, fsource.getType(), tsource,
-                                               /*shape*/ mlir::Value{},
-                                               /*slice=*/mlir::Value{});
-
-    // builder.createConvert(loc, fsource.getType(), tsource);
+    tsourceCast = convertToStaticType(tsource, fsource);
   } else if (!fir::isPolymorphicType(tsource.getType()) &&
              fir::isPolymorphicType(fsource.getType())) {
-    fsourceCast = builder.create<fir::ReboxOp>(loc, tsource.getType(), fsource,
-                                               /*shape*/ mlir::Value{},
-                                               /*slice=*/mlir::Value{});
-
-    // fsourceCast = builder.createConvert(loc, tsource.getType(), fsource);
+    fsourceCast = convertToStaticType(fsource, tsource);
   } else {
     // FSOURCE and TSOURCE are not polymorphic.
     // FSOURCE has the same type as TSOURCE, but they may not have the same MLIR

diff  --git a/flang/test/Lower/HLFIR/calls-character-singleton-result.f90 b/flang/test/Lower/HLFIR/calls-character-singleton-result.f90
index 0ef8490f7b776..3a3277c835645 100644
--- a/flang/test/Lower/HLFIR/calls-character-singleton-result.f90
+++ b/flang/test/Lower/HLFIR/calls-character-singleton-result.f90
@@ -14,7 +14,7 @@ subroutine scalar_char(c, i)
 ! CHECK:  %[[VAL_4:.*]] = fir.convert %{{.*}}#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.char<1>>
 ! CHECK:  %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] typeparams %{{.*}}  {{.*}}Ec
 ! CHECK:  %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}}  {{.*}}Ei
-! CHECK:  %[[VAL_7:.*]] = fir.load %[[VAL_6]]#1 : !fir.ref<i64>
+! CHECK:  %[[VAL_7:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<i64>
 ! CHECK:  %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> i8
 ! CHECK:  %[[VAL_9:.*]] = fir.undefined !fir.char<1>
 ! CHECK:  %[[VAL_10:.*]] = fir.insert_value %[[VAL_9]], %[[VAL_8]], [0 : index] : (!fir.char<1>, i8) -> !fir.char<1>

diff  --git a/flang/test/Lower/HLFIR/calls-f77.f90 b/flang/test/Lower/HLFIR/calls-f77.f90
index d736865a41beb..ec78718d513cf 100644
--- a/flang/test/Lower/HLFIR/calls-f77.f90
+++ b/flang/test/Lower/HLFIR/calls-f77.f90
@@ -157,7 +157,7 @@ subroutine return_char(n)
 ! CHECK-LABEL: func.func @_QPreturn_char(
 ! CHECK:  %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}n
 ! CHECK:  %[[VAL_2:.*]] = arith.constant -1 : i32
-! CHECK:  %[[VAL_7:.*]] = fir.load %[[VAL_1]]#1 : !fir.ref<i64>
+! CHECK:  %[[VAL_7:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i64>
 ! CHECK:  %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
 ! CHECK:  %[[VAL_9:.*]] = arith.constant 0 : index
 ! CHECK:  %[[VAL_10:.*]] = arith.cmpi sgt, %[[VAL_8]], %[[VAL_9]] : index

diff  --git a/flang/test/Lower/HLFIR/convert-mbox-to-value.f90 b/flang/test/Lower/HLFIR/convert-mbox-to-value.f90
index 7c33beb16a0c1..52b9804fadc05 100644
--- a/flang/test/Lower/HLFIR/convert-mbox-to-value.f90
+++ b/flang/test/Lower/HLFIR/convert-mbox-to-value.f90
@@ -54,12 +54,13 @@ end subroutine test_char_allocatable
 ! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFtest_char_allocatableEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
 ! CHECK:           %[[VAL_5:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,11>>>>
 ! CHECK:           %[[VAL_6:.*]] = fir.box_addr %[[VAL_5]] : (!fir.box<!fir.heap<!fir.char<1,11>>>) -> !fir.heap<!fir.char<1,11>>
+! CHECK:           %[[VAL_1B:.*]] = arith.constant 11 : index
 ! CHECK:           %[[VAL_7:.*]] = arith.constant 1 : index
 ! CHECK:           %[[VAL_8:.*]] = arith.constant -1 : index
 ! CHECK:           %[[VAL_9:.*]] = arith.constant 0 : index
 ! CHECK:           %[[VAL_10:.*]] = arith.constant true
 ! CHECK:           %[[VAL_11:.*]] = arith.constant 32 : i8
-! CHECK:           %[[VAL_12:.*]] = arith.subi %[[VAL_1]], %[[VAL_7]] : index
+! CHECK:           %[[VAL_12:.*]] = arith.subi %[[VAL_1B]], %[[VAL_7]] : index
 ! CHECK:           %[[VAL_13:.*]]:2 = fir.iterate_while (%[[VAL_14:.*]] = %[[VAL_12]] to %[[VAL_9]] step %[[VAL_8]]) and (%[[VAL_15:.*]] = %[[VAL_10]]) iter_args(%[[VAL_16:.*]] = %[[VAL_12]]) -> (index) {
 ! CHECK:             %[[VAL_17:.*]] = fir.convert %[[VAL_6]] : (!fir.heap<!fir.char<1,11>>) -> !fir.ref<!fir.array<11x!fir.char<1>>>
 ! CHECK:             %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_17]], %[[VAL_14]] : (!fir.ref<!fir.array<11x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
@@ -88,12 +89,13 @@ end subroutine test_char_pointer
 ! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %[[VAL_3]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_char_pointerEp"} : (!fir.ref<!fir.box<!fir.ptr<!fir.char<1,11>>>>, index) -> (!fir.ref<!fir.box<!fir.ptr<!fir.char<1,11>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.char<1,11>>>>)
 ! CHECK:           %[[VAL_5:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.char<1,11>>>>
 ! CHECK:           %[[VAL_6:.*]] = fir.box_addr %[[VAL_5]] : (!fir.box<!fir.ptr<!fir.char<1,11>>>) -> !fir.ptr<!fir.char<1,11>>
+! CHECK:           %[[VAL_3B:.*]] = arith.constant 11 : index
 ! CHECK:           %[[VAL_7:.*]] = arith.constant 1 : index
 ! CHECK:           %[[VAL_8:.*]] = arith.constant -1 : index
 ! CHECK:           %[[VAL_9:.*]] = arith.constant 0 : index
 ! CHECK:           %[[VAL_10:.*]] = arith.constant true
 ! CHECK:           %[[VAL_11:.*]] = arith.constant 32 : i8
-! CHECK:           %[[VAL_12:.*]] = arith.subi %[[VAL_3]], %[[VAL_7]] : index
+! CHECK:           %[[VAL_12:.*]] = arith.subi %[[VAL_3B]], %[[VAL_7]] : index
 ! CHECK:           %[[VAL_13:.*]]:2 = fir.iterate_while (%[[VAL_14:.*]] = %[[VAL_12]] to %[[VAL_9]] step %[[VAL_8]]) and (%[[VAL_15:.*]] = %[[VAL_10]]) iter_args(%[[VAL_16:.*]] = %[[VAL_12]]) -> (index) {
 ! CHECK:             %[[VAL_17:.*]] = fir.convert %[[VAL_6]] : (!fir.ptr<!fir.char<1,11>>) -> !fir.ref<!fir.array<11x!fir.char<1>>>
 ! CHECK:             %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_17]], %[[VAL_14]] : (!fir.ref<!fir.array<11x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
@@ -205,14 +207,15 @@ end subroutine test_derived_allocatable
 ! CHECK:           %[[VAL_12:.*]] = fir.embox %[[VAL_11]] : (!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>) -> !fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>
 ! CHECK:           fir.store %[[VAL_12]] to %[[VAL_10]] : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
 ! CHECK:           %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_10]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_derived_allocatableEr"} : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>) -> (!fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>, !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>)
-! CHECK:           %[[VAL_14:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
-! CHECK:           %[[VAL_15:.*]] = fir.load %[[VAL_8]]#1 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
-! CHECK:           %[[VAL_16:.*]] = fir.load %[[VAL_9]]#1 : !fir.ref<!fir.logical<4>>
+! CHECK:           %[[VAL_14:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
+! CHECK:           %[[VAL_14B:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>) -> !fir.heap<!fir.type<_QFtest_derived_allocatableTt>>
+! CHECK:           %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
+! CHECK:           %[[VAL_16:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<!fir.logical<4>>
 ! CHECK:           %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.logical<4>) -> i1
-! CHECK:           %[[VAL_18:.*]] = fir.rebox %[[VAL_15]] : (!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>) -> !fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>
-! CHECK:           %[[VAL_19:.*]] = arith.select %[[VAL_17]], %[[VAL_14]], %[[VAL_18]] : !fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>
-! CHECK:           %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>) -> (!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>, !fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>)
-! CHECK:           %[[VAL_21:.*]] = hlfir.as_expr %[[VAL_20]]#0 : (!fir.box<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>) -> !hlfir.expr<!fir.type<_QFtest_derived_allocatableTt>>
+! CHECK:           %[[VAL_18:.*]] = fir.box_addr %[[VAL_15]] : (!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>) -> !fir.heap<!fir.type<_QFtest_derived_allocatableTt>>
+! CHECK:           %[[VAL_19:.*]] = arith.select %[[VAL_17]], %[[VAL_14B]], %[[VAL_18]] : !fir.heap<!fir.type<_QFtest_derived_allocatableTt>>
+! CHECK:           %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>) -> (!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>, !fir.heap<!fir.type<_QFtest_derived_allocatableTt>>)
+! CHECK:           %[[VAL_21:.*]] = hlfir.as_expr %[[VAL_20]]#0 : (!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>) -> !hlfir.expr<!fir.type<_QFtest_derived_allocatableTt>>
 ! CHECK:           hlfir.assign %[[VAL_21]] to %[[VAL_13]]#0 realloc : !hlfir.expr<!fir.type<_QFtest_derived_allocatableTt>>, !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_allocatableTt>>>>
 ! CHECK:           hlfir.destroy %[[VAL_21]] : !hlfir.expr<!fir.type<_QFtest_derived_allocatableTt>>
 ! CHECK:           return
@@ -244,14 +247,15 @@ end subroutine test_derived_pointer
 ! CHECK:           %[[VAL_12:.*]] = fir.embox %[[VAL_11]] : (!fir.heap<!fir.type<_QFtest_derived_pointerTt>>) -> !fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>
 ! CHECK:           fir.store %[[VAL_12]] to %[[VAL_10]] : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>
 ! CHECK:           %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_10]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_derived_pointerEr"} : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>) -> (!fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>, !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>)
-! CHECK:           %[[VAL_14:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>>
-! CHECK:           %[[VAL_15:.*]] = fir.load %[[VAL_8]]#1 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>
-! CHECK:           %[[VAL_16:.*]] = fir.load %[[VAL_9]]#1 : !fir.ref<!fir.logical<4>>
+! CHECK:           %[[VAL_14:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>>
+! CHECK:           %[[VAL_14B:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>) -> !fir.ptr<!fir.type<_QFtest_derived_pointerTt>>
+! CHECK:           %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>
+! CHECK:           %[[VAL_16:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<!fir.logical<4>>
 ! CHECK:           %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.logical<4>) -> i1
-! CHECK:           %[[VAL_18:.*]] = fir.rebox %[[VAL_15]] : (!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>) -> !fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>
-! CHECK:           %[[VAL_19:.*]] = arith.select %[[VAL_17]], %[[VAL_14]], %[[VAL_18]] : !fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>
-! CHECK:           %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>) -> (!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>, !fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>)
-! CHECK:           %[[VAL_21:.*]] = hlfir.as_expr %[[VAL_20]]#0 : (!fir.box<!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>>) -> !hlfir.expr<!fir.type<_QFtest_derived_pointerTt>>
+! CHECK:           %[[VAL_18:.*]] = fir.box_addr %[[VAL_15]] : (!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>) -> !fir.ptr<!fir.type<_QFtest_derived_pointerTt>>
+! CHECK:           %[[VAL_19:.*]] = arith.select %[[VAL_17]], %[[VAL_14B]], %[[VAL_18]] : !fir.ptr<!fir.type<_QFtest_derived_pointerTt>>
+! CHECK:           %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>) -> (!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>, !fir.ptr<!fir.type<_QFtest_derived_pointerTt>>)
+! CHECK:           %[[VAL_21:.*]] = hlfir.as_expr %[[VAL_20]]#0 : (!fir.ptr<!fir.type<_QFtest_derived_pointerTt>>) -> !hlfir.expr<!fir.type<_QFtest_derived_pointerTt>>
 ! CHECK:           hlfir.assign %[[VAL_21]] to %[[VAL_13]]#0 realloc : !hlfir.expr<!fir.type<_QFtest_derived_pointerTt>>, !fir.ref<!fir.class<!fir.heap<!fir.type<_QFtest_derived_pointerTt>>>>
 ! CHECK:           hlfir.destroy %[[VAL_21]] : !hlfir.expr<!fir.type<_QFtest_derived_pointerTt>>
 ! CHECK:           return

diff  --git a/flang/test/Lower/HLFIR/expr-as-inquired.f90 b/flang/test/Lower/HLFIR/expr-as-inquired.f90
index 1186d08c9f3f9..455ddf6a44281 100644
--- a/flang/test/Lower/HLFIR/expr-as-inquired.f90
+++ b/flang/test/Lower/HLFIR/expr-as-inquired.f90
@@ -33,7 +33,7 @@ subroutine test_lbound(x, n)
 ! CHECK:  %[[VAL_7:.*]] = arith.constant 3 : i64
 ! CHECK:  %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
 ! CHECK:  %[[VAL_10:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}})  {{.*}}Ex
-! CHECK:  %[[VAL_11:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<i32>
+! CHECK:  %[[VAL_11:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i32>
 ! CHECK:  %[[VAL_12:.*]] = fir.shift %[[VAL_6]], %[[VAL_8]] : (index, index) -> !fir.shift<2>
 ! CHECK:  %[[VAL_13:.*]] = fir.rebox %[[VAL_10]]#1(%[[VAL_12]]) : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
 ! CHECK:  %[[VAL_16:.*]] = fir.convert %[[VAL_13]] : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<none>

diff  --git a/flang/test/Lower/HLFIR/expr-value.f90 b/flang/test/Lower/HLFIR/expr-value.f90
index bcb5f4deae29b..cd2f42533c273 100644
--- a/flang/test/Lower/HLFIR/expr-value.f90
+++ b/flang/test/Lower/HLFIR/expr-value.f90
@@ -13,6 +13,6 @@ subroutine foo()
 subroutine foo_designator(n)
   !CHECK:  %[[n:.*]]:2 = hlfir.declare %[[arg0]] {uniq_name = "_QFfoo_designatorEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
   print *, n
-  ! CHECK: %[[nval:.*]] = fir.load %[[n]]#1 : !fir.ref<i32>
+  ! CHECK: %[[nval:.*]] = fir.load %[[n]]#0 : !fir.ref<i32>
   ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[nval]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
 end subroutine

diff  --git a/flang/test/Lower/HLFIR/forall.f90 b/flang/test/Lower/HLFIR/forall.f90
index 1485ceb60559a..9941ed1940103 100644
--- a/flang/test/Lower/HLFIR/forall.f90
+++ b/flang/test/Lower/HLFIR/forall.f90
@@ -52,7 +52,7 @@ subroutine test_forall_step(step)
 ! CHECK:  %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Estep
 ! CHECK:  %[[VAL_7:.*]]:2 = hlfir.declare {{.*}}Ex
 ! CHECK:  %[[VAL_10:.*]]:2 = hlfir.declare {{.*}}Ey
-! CHECK:  %[[VAL_11:.*]] = fir.load %[[VAL_4]]#1 : !fir.ref<i32>
+! CHECK:  %[[VAL_11:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i32>
 ! CHECK:  hlfir.forall lb {
 ! CHECK:    hlfir.yield %[[VAL_2]] : i32
 ! CHECK:  } ub {


        


More information about the flang-commits mailing list