Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def AnyRefOfConstantSizeAggregateType : TypeConstraint<
// Memory SSA operations
//===----------------------------------------------------------------------===//

def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
MemoryEffects<[MemAlloc<AutomaticAllocationScopeResource>]>]> {
def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments]> {
let summary = "allocate storage for a temporary on the stack given a type";
let description = [{
This primitive operation is used to allocate an object on the stack. A
Expand Down Expand Up @@ -162,7 +161,9 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
Variadic<AnyIntegerType>:$shape
);

let results = (outs fir_ReferenceType);
let results =
(outs Res<fir_ReferenceType,
"", [MemAlloc<AutomaticAllocationScopeResource>]>:$res);

let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
Expand Down Expand Up @@ -212,8 +213,7 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
}];
}

def fir_AllocMemOp : fir_Op<"allocmem",
[MemoryEffects<[MemAlloc<DefaultResource>]>, AttrSizedOperandSegments]> {
def fir_AllocMemOp : fir_Op<"allocmem", [AttrSizedOperandSegments]> {
let summary = "allocate storage on the heap for an object of a given type";

let description = [{
Expand All @@ -235,7 +235,7 @@ def fir_AllocMemOp : fir_Op<"allocmem",
Variadic<AnyIntegerType>:$typeparams,
Variadic<AnyIntegerType>:$shape
);
let results = (outs fir_HeapType);
let results = (outs Res<fir_HeapType, "", [MemAlloc<DefaultResource>]>:$res);

let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
Expand Down
57 changes: 42 additions & 15 deletions flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ using namespace mlir;

#define DEBUG_TYPE "fir-alias-analysis"

// Inspect for value-scoped Allocate effects and determine whether
// 'candidate' is a new allocation. Returns SourceKind::Allocate if a
// MemAlloc effect is attached
static fir::AliasAnalysis::SourceKind
classifyAllocateFromEffects(mlir::Operation *op, mlir::Value candidate) {
if (!op)
return fir::AliasAnalysis::SourceKind::Unknown;
auto interface = llvm::dyn_cast<mlir::MemoryEffectOpInterface>(op);
if (!interface)
return fir::AliasAnalysis::SourceKind::Unknown;
llvm::SmallVector<mlir::MemoryEffects::EffectInstance, 4> effects;
interface.getEffects(effects);
for (mlir::MemoryEffects::EffectInstance &e : effects) {
if (mlir::isa<mlir::MemoryEffects::Allocate>(e.getEffect()) &&
e.getValue() && e.getValue() == candidate)
return fir::AliasAnalysis::SourceKind::Allocate;
}
return fir::AliasAnalysis::SourceKind::Unknown;
}

//===----------------------------------------------------------------------===//
// AliasAnalysis: alias
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -535,6 +555,11 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
mlir::Operation *instantiationPoint{nullptr};
while (defOp && !breakFromLoop) {
ty = defOp->getResultTypes()[0];
// Value-scoped allocation detection via effects.
if (classifyAllocateFromEffects(defOp, v) == SourceKind::Allocate) {
type = SourceKind::Allocate;
break;
}
llvm::TypeSwitch<Operation *>(defOp)
.Case<hlfir::AsExprOp>([&](auto op) {
v = op.getVar();
Expand All @@ -554,11 +579,6 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
defOp = v.getDefiningOp();
}
})
.Case<fir::AllocaOp, fir::AllocMemOp>([&](auto op) {
// Unique memory allocation.
type = SourceKind::Allocate;
breakFromLoop = true;
})
.Case<fir::ConvertOp>([&](auto op) {
// Skip ConvertOp's and track further through the operand.
v = op->getOperand(0);
Expand Down Expand Up @@ -628,16 +648,23 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
type = SourceKind::Global;
} else {
auto def = llvm::cast<mlir::Value>(boxSrc.origin.u);
// TODO: Add support to fir.allocmem
if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
v = def;
defOp = v.getDefiningOp();
type = SourceKind::Allocate;
} else if (isDummyArgument(def)) {
defOp = nullptr;
v = def;
} else {
type = SourceKind::Indirect;
bool classified = false;
if (auto defDefOp = def.getDefiningOp()) {
if (classifyAllocateFromEffects(defDefOp, def) ==
SourceKind::Allocate) {
v = def;
defOp = defDefOp;
type = SourceKind::Allocate;
classified = true;
}
}
if (!classified) {
if (isDummyArgument(def)) {
defOp = nullptr;
v = def;
} else {
type = SourceKind::Indirect;
}
}
}
breakFromLoop = true;
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Driver/tco-emit-final-mlir.fir
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@

func.func @_QPfoo() {
%1 = fir.alloca i32
%0 = arith.constant 0 : i32
fir.store %0 to %1 : !fir.ref<i32>
return
}
9 changes: 9 additions & 0 deletions flang/test/Fir/alloc.fir
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,17 @@ func.func @alloca_unlimited_polymorphic_box() {
%1 = fir.alloca !fir.class<!fir.array<?xnone>>
%2 = fir.alloca !fir.box<none>
%3 = fir.alloca !fir.box<!fir.array<?xnone>>
// Add real uses so allocas are not trivially dead.
func.call @__use_class_none(%0) : (!fir.ref<!fir.class<none>>) -> ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use fir.call instead?

func.call @__use_class_array(%1) : (!fir.ref<!fir.class<!fir.array<?xnone>>>) -> ()
func.call @__use_box_none(%2) : (!fir.ref<!fir.box<none>>) -> ()
func.call @__use_box_array(%3) : (!fir.ref<!fir.box<!fir.array<?xnone>>>) -> ()
return
}
func.func private @__use_class_none(!fir.ref<!fir.class<none>>) -> ()
func.func private @__use_class_array(!fir.ref<!fir.class<!fir.array<?xnone>>>) -> ()
func.func private @__use_box_none(!fir.ref<!fir.box<none>>) -> ()
func.func private @__use_box_array(!fir.ref<!fir.box<!fir.array<?xnone>>>) -> ()
// Note: allocmem of fir.box are not possible (fir::HeapType::verify does not
// accept box types), so there is no equivalent of
// alloca_unlimited_polymorphic_box for allocmem.
4 changes: 4 additions & 0 deletions flang/test/Fir/omp-reduction-embox-codegen.fir
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ omp.declare_reduction @test_reduction : !fir.ref<!fir.box<i32>> init {
^bb0(%arg0: !fir.ref<!fir.box<i32>>):
%0 = fir.alloca !fir.box<i32>
%1 = fir.alloca i32
%c0 = arith.constant 0 : i32
fir.store %c0 to %1 : !fir.ref<i32>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why we need this. Both %0 and %1 are directly or indirectly used by fir.store, so they should not become dead.

%2 = fir.embox %1 : (!fir.ref<i32>) -> !fir.box<i32>

// use the embox for something so it isn't removed
Expand All @@ -28,9 +30,11 @@ func.func @_QQmain() attributes {fir.bindc_name = "reduce"} {
omp.parallel reduction(byref @test_reduction %4 -> %arg0 : !fir.ref<!fir.box<i32>>) {
omp.terminator
}
func.call @__use_box_i32(%4) : (!fir.ref<!fir.box<i32>>) -> ()
return
}

func.func private @__use_box_i32(!fir.ref<!fir.box<i32>>) -> ()
// basically we are testing that there isn't a crash
// CHECK-LABEL: define void @_QQmain
// CHECK-NEXT: alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
6 changes: 3 additions & 3 deletions flang/test/Fir/pdt.fir
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ func.func @_QTt1P.f2.offset(%0 : i32, %1 : i32) -> i32 {
// end program p

func.func private @bar(!fir.ref<!fir.char<1,?>>)
func.func private @__use_t1(!fir.ref<!fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>>) -> ()

// CHECK-LABEL: define void @_QPfoo(i32 %0, i32 %1)
func.func @_QPfoo(%arg0 : i32, %arg1 : i32) {
// CHECK: %[[size:.*]] = call i64 @_QTt1P.mem.size(i32 %0, i32 %1)
// CHECK: %[[alloc:.*]] = alloca i8, i64 %[[size]]
%0 = fir.alloca !fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>(%arg0, %arg1 : i32, i32)
//%2 = fir.coordinate_of %0, f2 : (!fir.ref<!fir.type<_QTt1>>) -> !fir.ref<!fir.char<1,?>>
%2 = fir.zero_bits !fir.ref<!fir.char<1,?>>
fir.call @bar(%2) : (!fir.ref<!fir.char<1,?>>) -> ()
// Keep alloca live without creating an unsupported coordinate_of on dynamic-sized field.
func.call @__use_t1(%0) : (!fir.ref<!fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>>) -> ()
return
}
12 changes: 12 additions & 0 deletions flang/test/HLFIR/inline-hlfir-copy-in.fir
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func.func private @_test_inline_copy_in(%arg0: !fir.box<!fir.array<?x?x?xf64>> {
fir.call @_QFPsb(%18, %19#0) fastmath<contract> : (!fir.ref<!fir.array<?xf64>>, !fir.ref<i32>) -> ()
hlfir.copy_out %0, %17#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1) -> ()
hlfir.end_associate %19#1, %19#2 : !fir.ref<i32>, i1
// Keep %0 live to avoid DCE after inlining when no copy_out is needed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I do not get what happens in this case - can you please explain? I think we do not have to insert the fake use here.

%zb0 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf64>>>
fir.store %zb0 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>
return
}

Expand Down Expand Up @@ -110,6 +113,9 @@ func.func private @_test_no_inline_copy_in(%arg0: !fir.box<!fir.array<?x?x?xf64>
fir.call @_QFPsb(%18, %19#1) fastmath<contract> : (!fir.ref<!fir.array<?xf64>>, !fir.ref<i32>) -> ()
hlfir.copy_out %0, %17#1 to %16 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1, !fir.box<!fir.array<?xf64>>) -> ()
hlfir.end_associate %19#1, %19#2 : !fir.ref<i32>, i1
// Keep %0 live to avoid DCE after inlining.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: no need for a fake use.

%zb1 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf64>>>
fir.store %zb1 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>
return
}

Expand Down Expand Up @@ -160,6 +166,9 @@ func.func @_QPoptional_copy_in_out(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc
}
fir.call @_QPtakes_optional_explicit(%4#0) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
hlfir.copy_out %0, %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, i1) -> ()
// Keep %0 live to avoid DCE after inlining.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: no need for a fake use.

%zb2 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf32>>>
fir.store %zb2 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
return
}

Expand Down Expand Up @@ -191,6 +200,9 @@ func.func @_QPtest_copy_in_out_2(%arg0: !fir.box<!fir.array<*:f32>> {fir.bindc_n
%3:2 = hlfir.copy_in %2#0 to %0 : (!fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> (!fir.box<!fir.array<*:f32>>, i1)
fir.call @_QPtakes_contiguous_intentin(%3#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> ()
hlfir.copy_out %0, %3#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, i1) -> ()
// Keep %0 live to avoid DCE after inlining.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: no need for a fake use.

%zb3 = fir.zero_bits !fir.box<!fir.heap<!fir.array<*:f32>>>
fir.store %zb3 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>
return
}

Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/Intrinsics/c_f_pointer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ subroutine dynamic_shape_lower(cptr, fpr, shape, lower)
! CHECK: %[[VAL_2:.*]] = fir.shape %[[C_0]], %[[C_0]] : (index, index) -> !fir.shape<2>
! CHECK: %[[VAL_3:.*]] = fir.embox %[[VAL_1:.*]](%[[VAL_2]]) : (!fir.ptr<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
! CHECK: fir.store %[[VAL_3]] to %[[VAL_0:.*]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
! CHECK: %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "n", uniq_name = "_QFdynamic_shape_lowerEn"}
! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[ARG_0:.*]], __address : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> !fir.ref<i64>
! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> !fir.ptr<!fir.array<?x?xf32>>
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Lower/Intrinsics/system_clock.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ subroutine system_clock_test()

! CHECK-LABEL: @_QPss
subroutine ss(count)
! CHECK: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<i64>> {bindc_name = "count_max", uniq_name = "_QFssEcount_max"}
! CHECK: %[[V_1:[0-9]+]] = fir.alloca !fir.heap<i64> {uniq_name = "_QFssEcount_max.addr"}
! CHECK: %[[V_2:[0-9]+]] = fir.zero_bits !fir.heap<i64>
! CHECK: fir.store %[[V_2]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_3:[0-9]+]] = fir.alloca !fir.box<!fir.ptr<i64>> {bindc_name = "count_rate", uniq_name = "_QFssEcount_rate"}
! CHECK: %[[V_4:[0-9]+]] = fir.alloca !fir.ptr<i64> {uniq_name = "_QFssEcount_rate.addr"}
! CHECK: %[[V_5:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
! CHECK: fir.store %[[V_5]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
Expand Down
6 changes: 1 addition & 5 deletions flang/test/Lower/allocatables.f90
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ subroutine foodim1()
! CHECK-DAG: fir.load %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>

deallocate(x)
! CHECK: %[[xAddr1:.*]] = fir.load %1 : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: %[[xAddr1:.*]] = fir.load %{{.*}} : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: fir.freemem %[[xAddr1]]
! CHECK: %[[nullAddr1:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
! CHECK: fir.store %[[nullAddr1]] to %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
Expand All @@ -67,10 +67,6 @@ subroutine foodim2()
! Test lowering of local allocatable specification
real, allocatable :: x(:, :)
! CHECK-DAG: fir.alloca !fir.heap<!fir.array<?x?xf32>> {{{.*}}uniq_name = "_QFfoodim2Ex.addr"}
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.lb0"}
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.ext0"}
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.lb1"}
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.ext1"}
end subroutine

! test lowering of character allocatables. Focus is placed on the length handling
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Lower/character-local-variables.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
subroutine scalar_cst_len()
character(10) :: c
! CHECK: fir.alloca !fir.char<1,10> {{{.*}}uniq_name = "_QFscalar_cst_lenEc"}
print *, c
end subroutine

! CHECK-LABEL: func @_QPscalar_dyn_len
Expand All @@ -19,12 +20,14 @@ subroutine scalar_dyn_len(l)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
! CHECK: fir.alloca !fir.char<1,?>(%[[l]] : i32) {{{.*}}uniq_name = "_QFscalar_dyn_lenEc"}
print *, c
end subroutine

! CHECK-LABEL: func @_QPcst_array_cst_len
subroutine cst_array_cst_len()
character(10) :: c(20)
! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_lenEc"}
print *, c(1)
end subroutine

! CHECK-LABEL: func @_QPcst_array_dyn_len
Expand All @@ -36,6 +39,7 @@ subroutine cst_array_dyn_len(l)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i32
! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i32
! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i32) {{{.*}}uniq_name = "_QFcst_array_dyn_lenEc"}
print *, c(1)
end subroutine

! CHECK-LABEL: func @_QPdyn_array_cst_len
Expand All @@ -48,6 +52,7 @@ subroutine dyn_array_cst_len(n)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_lenEc"}
print *, c(1)
end subroutine

! CHECK: func @_QPdyn_array_dyn_len
Expand All @@ -63,12 +68,14 @@ subroutine dyn_array_dyn_len(l, n)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[ni]], %c0{{.*}} : index
! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[ni]], %c0{{.*}} : index
! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i32), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_lenEc"}
print *, c(1)
end subroutine

! CHECK-LABEL: func @_QPcst_array_cst_len_lb
subroutine cst_array_cst_len_lb()
character(10) :: c(11:30)
! CHECK: fir.alloca !fir.array<20x!fir.char<1,10>> {{{.*}}uniq_name = "_QFcst_array_cst_len_lbEc"}
print *, c(11)
end subroutine

! CHECK-LABEL: func @_QPcst_array_dyn_len_lb
Expand All @@ -80,6 +87,7 @@ subroutine cst_array_dyn_len_lb(l)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[lexpr]], %c0{{.*}} : i64
! CHECK: %[[l:.*]] = arith.select %[[is_positive]], %[[lexpr]], %c0{{.*}} : i64
! CHECK: fir.alloca !fir.array<10x!fir.char<1,?>>(%[[l]] : i64) {{{.*}}uniq_name = "_QFcst_array_dyn_len_lbEc"}
print *, c(11)
end subroutine

! CHECK-LABEL: func @_QPdyn_array_cst_len_lb
Expand All @@ -94,6 +102,7 @@ subroutine dyn_array_cst_len_lb(n)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
! CHECK: fir.alloca !fir.array<?x!fir.char<1,10>>, %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_cst_len_lbEc"}
print *, c(11)
end subroutine

! CHECK-LABEL: func @_QPdyn_array_dyn_len_lb
Expand All @@ -111,6 +120,7 @@ subroutine dyn_array_dyn_len_lb(l, n)
! CHECK: %[[is_positive:.*]] = arith.cmpi sgt, %[[raw_extent]], %c0{{.*}} : index
! CHECK: %[[extent:.*]] = arith.select %[[is_positive]], %[[raw_extent]], %c0{{.*}} : index
! CHECK: fir.alloca !fir.array<?x!fir.char<1,?>>(%[[l]] : i64), %[[extent]] {{{.*}}uniq_name = "_QFdyn_array_dyn_len_lbEc"}
print *, c(11)
end subroutine

! Test that the length of assumed length parameter is correctly deduced in lowering.
Expand All @@ -129,4 +139,5 @@ subroutine assumed_length_param(n)
subroutine scalar_cst_neg_len()
character(-1) :: c
! CHECK: fir.alloca !fir.char<1,0> {{{.*}}uniq_name = "_QFscalar_cst_neg_lenEc"}
print *, c
end subroutine
2 changes: 0 additions & 2 deletions flang/test/Lower/derived-types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ subroutine derived_dummy(some_r, some_c2)

! CHECK-LABEL: func @_QMdPlocal_derived(
subroutine local_derived()
! CHECK-DAG: fir.alloca !fir.type<_QMdTc2{ch_array:!fir.array<20x30x!fir.char<1,10>>}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep these checks by adding fake uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed! please check the most updated commit. for some the llvm diff doesn't show this being outdated

! CHECK-DAG: fir.alloca !fir.type<_QMdTr{x:f32}>
type(r) :: some_r
type(c2) :: some_c2
end subroutine
Expand Down
6 changes: 1 addition & 5 deletions flang/test/Lower/do_loop_unstructured.f90
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,5 @@ subroutine unstructured_do_concurrent
! CHECK: ^[[HEADER]]:
! CHECK: %{{.*}} = fir.load %[[ITER_VAR]] : !fir.ref<i32>
! CHECK: cf.cond_br %{{.*}}, ^[[BODY:.*]], ^[[EXIT:.*]]

! CHECK: ^[[BODY]]:
! CHECK-NEXT: %{{.*}} = fir.alloca !fir.logical<4> {bindc_name = "success", {{.*}}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some fake use here (e.g. a store into success).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed! please check the most updated commit. for some the llvm diff doesn't show this being outdated


! CHECK: ^[[EXIT]]:
! CHECK-NEXT: return
! CHECK: return
1 change: 0 additions & 1 deletion flang/test/Lower/forall/array-pointer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ end subroutine s2_3
! CHECK-LABEL: func @_QPs2_3(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<_QMarray_of_pointer_testTt{ip:!fir.box<!fir.ptr<i32>>}>>> {fir.bindc_name = "x"}) {
! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "y", fir.target, uniq_name = "_QFs2_3Ey"}
! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.heap<!fir.array<?xi32>> {uniq_name = "_QFs2_3Ey.addr"}
! CHECK: %[[VAL_4:.*]] = fir.alloca index {uniq_name = "_QFs2_3Ey.lb0"}
! CHECK: %[[VAL_5:.*]] = fir.alloca index {uniq_name = "_QFs2_3Ey.ext0"}
Expand Down
Loading