Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.
fir.call @__use_class_none(%0) : (!fir.ref<!fir.class<none>>) -> ()
fir.call @__use_class_array(%1) : (!fir.ref<!fir.class<!fir.array<?xnone>>>) -> ()
fir.call @__use_box_none(%2) : (!fir.ref<!fir.box<none>>) -> ()
fir.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.
2 changes: 2 additions & 0 deletions flang/test/Fir/omp-reduction-embox-codegen.fir
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,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
}
2 changes: 1 addition & 1 deletion flang/test/HLFIR/inline-hlfir-copy-in.fir
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func.func private @_test_inline_copy_in(%arg0: !fir.box<!fir.array<?x?x?xf64>> {
// CHECK: %[[VAL_22:.*]] = fir.box_addr %[[VAL_21:.*]]#0 : (!fir.box<!fir.array<?xf64>>) -> !fir.ref<!fir.array<?xf64>>
// CHECK: %[[VAL_23:.*]]:3 = hlfir.associate %[[VAL_5:.*]] {adapt.valuebyref} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
// CHECK: fir.call @_QFPsb(%[[VAL_22:.*]], %[[VAL_23:.*]]#0) fastmath<contract> : (!fir.ref<!fir.array<?xf64>>, !fir.ref<i32>) -> ()
// CHECK: hlfir.copy_out %16, %15#1 : (!fir.ref<!fir.box<!fir.array<?xf64>>>, i1) -> ()
// CHECK: hlfir.copy_out %{{.*}}, %[[VAL_21:.*]]#1 : (!fir.ref<!fir.box<!fir.array<?xf64>>>, i1) -> ()
// CHECK: hlfir.end_associate %[[VAL_23:.*]]#1, %[[VAL_23:.*]]#2 : !fir.ref<i32>, i1
// CHECK: return
// CHECK: }
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: 2 additions & 0 deletions flang/test/Lower/derived-types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ subroutine local_derived()
! CHECK-DAG: fir.alloca !fir.type<_QMdTr{x:f32}>
type(r) :: some_r
type(c2) :: some_c2
print *, some_c2%ch_array(1,1)
print *, some_r%x
end subroutine

! CHECK-LABEL: func @_QMdPsaved_derived(
Expand Down
1 change: 1 addition & 0 deletions flang/test/Lower/do_loop_unstructured.f90
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ subroutine nested_structured_in_unstructured()
subroutine unstructured_do_concurrent
logical :: success
do concurrent (i=1:10) local(success)
success = .false.
error stop "fail"
enddo
end
Expand Down
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
17 changes: 8 additions & 9 deletions flang/test/Lower/forall/forall-allocatable.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ end subroutine forall_with_allocatable
! CHECK-LABEL: func @_QPforall_with_allocatable(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"}
! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "arr", uniq_name = "_QFforall_with_allocatableEarr"}
! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.heap<!fir.array<?xf32>> {uniq_name = "_QFforall_with_allocatableEarr.addr"}
! CHECK: %[[VAL_4:.*]] = fir.alloca index {uniq_name = "_QFforall_with_allocatableEarr.lb0"}
! CHECK: %[[VAL_5:.*]] = fir.alloca index {uniq_name = "_QFforall_with_allocatableEarr.ext0"}
! CHECK: %[[VAL_6:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
! CHECK: fir.store %[[VAL_6]] to %[[VAL_3]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.heap<!fir.array<?xf32>> {uniq_name = "_QFforall_with_allocatableEarr.addr"}
! CHECK: %[[VAL_3:.*]] = fir.alloca index {uniq_name = "_QFforall_with_allocatableEarr.lb0"}
! CHECK: %[[VAL_4:.*]] = fir.alloca index {uniq_name = "_QFforall_with_allocatableEarr.ext0"}
! CHECK: %[[VAL_5:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
! CHECK: fir.store %[[VAL_5]] to %[[VAL_2]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: %[[VAL_7:.*]] = arith.constant 5 : i32
! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> index
! CHECK: %[[VAL_9:.*]] = arith.constant 15 : i32
! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i32) -> index
! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_4]] : !fir.ref<index>
! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_5]] : !fir.ref<index>
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_3]] : !fir.ref<index>
! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_4]] : !fir.ref<index>
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
! CHECK: %[[VAL_15:.*]] = fir.shape_shift %[[VAL_12]], %[[VAL_13]] : (index, index) -> !fir.shapeshift<1>
! CHECK: %[[VAL_16:.*]] = fir.array_load %[[VAL_14]](%[[VAL_15]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>) -> !fir.array<?xf32>
! CHECK: %[[VAL_17:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/loops.f90
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ subroutine lis(n)
! CHECK-DAG: fir.alloca !fir.array<?x?x?xi32>, %{{.*}}, %{{.*}}, %{{.*}} {bindc_name = "a", fir.target, uniq_name = "_QFlisEa"}
! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "r", uniq_name = "_QFlisEr"}
! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "s", uniq_name = "_QFlisEs"}
! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "t", uniq_name = "_QFlisEt"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a store into t to keep it alive.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ignore this comment. This fir.alloca is unused (due to local(t) below), and it does not add much to check for this alloca.

integer, target :: a(n,n,n) ! operand via p
integer :: r(n,n) ! result, unspecified locality
integer :: s(n,n) ! shared locality
Expand Down
Loading