Skip to content

Commit b9b30f5

Browse files
committed
change tests
1 parent d807d66 commit b9b30f5

18 files changed

+123
-136
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ def AnyRefOfConstantSizeAggregateType : TypeConstraint<
8080
// Memory SSA operations
8181
//===----------------------------------------------------------------------===//
8282

83-
def fir_AllocaOp
84-
: fir_Op<"alloca",
85-
[AttrSizedOperandSegments,
86-
MemoryEffects<[MemAlloc<AutomaticAllocationScopeResource>]>]> {
83+
def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments]> {
8784
let summary = "allocate storage for a temporary on the stack given a type";
8885
let description = [{
8986
This primitive operation is used to allocate an object on the stack. A
@@ -216,9 +213,7 @@ def fir_AllocaOp
216213
}];
217214
}
218215

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

224219
let description = [{

flang/test/Driver/tco-emit-final-mlir.fir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515

1616
func.func @_QPfoo() {
1717
%1 = fir.alloca i32
18+
%0 = arith.constant 0 : i32
19+
fir.store %0 to %1 : !fir.ref<i32>
1820
return
1921
}

flang/test/Fir/alloc.fir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,17 @@ func.func @alloca_unlimited_polymorphic_box() {
372372
%1 = fir.alloca !fir.class<!fir.array<?xnone>>
373373
%2 = fir.alloca !fir.box<none>
374374
%3 = fir.alloca !fir.box<!fir.array<?xnone>>
375+
// Add real uses so allocas are not trivially dead.
376+
func.call @__use_class_none(%0) : (!fir.ref<!fir.class<none>>) -> ()
377+
func.call @__use_class_array(%1) : (!fir.ref<!fir.class<!fir.array<?xnone>>>) -> ()
378+
func.call @__use_box_none(%2) : (!fir.ref<!fir.box<none>>) -> ()
379+
func.call @__use_box_array(%3) : (!fir.ref<!fir.box<!fir.array<?xnone>>>) -> ()
375380
return
376381
}
382+
func.func private @__use_class_none(!fir.ref<!fir.class<none>>) -> ()
383+
func.func private @__use_class_array(!fir.ref<!fir.class<!fir.array<?xnone>>>) -> ()
384+
func.func private @__use_box_none(!fir.ref<!fir.box<none>>) -> ()
385+
func.func private @__use_box_array(!fir.ref<!fir.box<!fir.array<?xnone>>>) -> ()
377386
// Note: allocmem of fir.box are not possible (fir::HeapType::verify does not
378387
// accept box types), so there is no equivalent of
379388
// alloca_unlimited_polymorphic_box for allocmem.

flang/test/Fir/omp-reduction-embox-codegen.fir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ omp.declare_reduction @test_reduction : !fir.ref<!fir.box<i32>> init {
1111
^bb0(%arg0: !fir.ref<!fir.box<i32>>):
1212
%0 = fir.alloca !fir.box<i32>
1313
%1 = fir.alloca i32
14+
%c0 = arith.constant 0 : i32
15+
fir.store %c0 to %1 : !fir.ref<i32>
1416
%2 = fir.embox %1 : (!fir.ref<i32>) -> !fir.box<i32>
1517

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

37+
func.func private @__use_box_i32(!fir.ref<!fir.box<i32>>) -> ()
3438
// basically we are testing that there isn't a crash
3539
// CHECK-LABEL: define void @_QQmain
3640
// CHECK-NEXT: alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8

flang/test/Fir/pdt.fir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ func.func @_QTt1P.f2.offset(%0 : i32, %1 : i32) -> i32 {
9595
// end program p
9696

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

99100
// CHECK-LABEL: define void @_QPfoo(i32 %0, i32 %1)
100101
func.func @_QPfoo(%arg0 : i32, %arg1 : i32) {
101102
// CHECK: %[[size:.*]] = call i64 @_QTt1P.mem.size(i32 %0, i32 %1)
102103
// CHECK: %[[alloc:.*]] = alloca i8, i64 %[[size]]
103104
%0 = fir.alloca !fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>(%arg0, %arg1 : i32, i32)
104-
//%2 = fir.coordinate_of %0, f2 : (!fir.ref<!fir.type<_QTt1>>) -> !fir.ref<!fir.char<1,?>>
105-
%2 = fir.zero_bits !fir.ref<!fir.char<1,?>>
106-
fir.call @bar(%2) : (!fir.ref<!fir.char<1,?>>) -> ()
105+
// Keep alloca live without creating an unsupported coordinate_of on dynamic-sized field.
106+
func.call @__use_t1(%0) : (!fir.ref<!fir.type<_QTt1(p1:i32,p2:i32){f1:!fir.char<1,?>,f2:!fir.char<1,?>}>>) -> ()
107107
return
108108
}

flang/test/HLFIR/inline-hlfir-copy-in.fir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func.func private @_test_inline_copy_in(%arg0: !fir.box<!fir.array<?x?x?xf64>> {
3131
fir.call @_QFPsb(%18, %19#0) fastmath<contract> : (!fir.ref<!fir.array<?xf64>>, !fir.ref<i32>) -> ()
3232
hlfir.copy_out %0, %17#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1) -> ()
3333
hlfir.end_associate %19#1, %19#2 : !fir.ref<i32>, i1
34+
// Keep %0 live to avoid DCE after inlining when no copy_out is needed.
35+
%zb0 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf64>>>
36+
fir.store %zb0 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>
3437
return
3538
}
3639

@@ -110,6 +113,9 @@ func.func private @_test_no_inline_copy_in(%arg0: !fir.box<!fir.array<?x?x?xf64>
110113
fir.call @_QFPsb(%18, %19#1) fastmath<contract> : (!fir.ref<!fir.array<?xf64>>, !fir.ref<i32>) -> ()
111114
hlfir.copy_out %0, %17#1 to %16 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1, !fir.box<!fir.array<?xf64>>) -> ()
112115
hlfir.end_associate %19#1, %19#2 : !fir.ref<i32>, i1
116+
// Keep %0 live to avoid DCE after inlining.
117+
%zb1 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf64>>>
118+
fir.store %zb1 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>
113119
return
114120
}
115121

@@ -160,6 +166,9 @@ func.func @_QPoptional_copy_in_out(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc
160166
}
161167
fir.call @_QPtakes_optional_explicit(%4#0) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
162168
hlfir.copy_out %0, %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, i1) -> ()
169+
// Keep %0 live to avoid DCE after inlining.
170+
%zb2 = fir.zero_bits !fir.box<!fir.heap<!fir.array<?xf32>>>
171+
fir.store %zb2 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
163172
return
164173
}
165174

@@ -191,6 +200,9 @@ func.func @_QPtest_copy_in_out_2(%arg0: !fir.box<!fir.array<*:f32>> {fir.bindc_n
191200
%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)
192201
fir.call @_QPtakes_contiguous_intentin(%3#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> ()
193202
hlfir.copy_out %0, %3#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, i1) -> ()
203+
// Keep %0 live to avoid DCE after inlining.
204+
%zb3 = fir.zero_bits !fir.box<!fir.heap<!fir.array<*:f32>>>
205+
fir.store %zb3 to %0 : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>
194206
return
195207
}
196208

flang/test/Lower/Intrinsics/c_f_pointer.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ subroutine dynamic_shape_lower(cptr, fpr, shape, lower)
153153
! CHECK: %[[VAL_2:.*]] = fir.shape %[[C_0]], %[[C_0]] : (index, index) -> !fir.shape<2>
154154
! 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>>>
155155
! CHECK: fir.store %[[VAL_3]] to %[[VAL_0:.*]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
156-
! CHECK: %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "n", uniq_name = "_QFdynamic_shape_lowerEn"}
157156
! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[ARG_0:.*]], __address : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> !fir.ref<i64>
158157
! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
159158
! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> !fir.ptr<!fir.array<?x?xf32>>

flang/test/Lower/Intrinsics/system_clock.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ subroutine system_clock_test()
3232

3333
! CHECK-LABEL: @_QPss
3434
subroutine ss(count)
35-
! CHECK: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<i64>> {bindc_name = "count_max", uniq_name = "_QFssEcount_max"}
3635
! CHECK: %[[V_1:[0-9]+]] = fir.alloca !fir.heap<i64> {uniq_name = "_QFssEcount_max.addr"}
3736
! CHECK: %[[V_2:[0-9]+]] = fir.zero_bits !fir.heap<i64>
3837
! CHECK: fir.store %[[V_2]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
39-
! CHECK: %[[V_3:[0-9]+]] = fir.alloca !fir.box<!fir.ptr<i64>> {bindc_name = "count_rate", uniq_name = "_QFssEcount_rate"}
4038
! CHECK: %[[V_4:[0-9]+]] = fir.alloca !fir.ptr<i64> {uniq_name = "_QFssEcount_rate.addr"}
4139
! CHECK: %[[V_5:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
4240
! CHECK: fir.store %[[V_5]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>

flang/test/Lower/allocatables.f90

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ subroutine foodim1()
5656
! CHECK-DAG: fir.load %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
5757

5858
deallocate(x)
59-
! CHECK: %[[xAddr1:.*]] = fir.load %1 : !fir.ref<!fir.heap<!fir.array<?xf32>>>
59+
! CHECK: %[[xAddr1:.*]] = fir.load %{{.*}} : !fir.ref<!fir.heap<!fir.array<?xf32>>>
6060
! CHECK: fir.freemem %[[xAddr1]]
6161
! CHECK: %[[nullAddr1:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>
6262
! CHECK: fir.store %[[nullAddr1]] to %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
@@ -67,10 +67,6 @@ subroutine foodim2()
6767
! Test lowering of local allocatable specification
6868
real, allocatable :: x(:, :)
6969
! CHECK-DAG: fir.alloca !fir.heap<!fir.array<?x?xf32>> {{{.*}}uniq_name = "_QFfoodim2Ex.addr"}
70-
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.lb0"}
71-
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.ext0"}
72-
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.lb1"}
73-
! CHECK-DAG: fir.alloca index {{{.*}}uniq_name = "_QFfoodim2Ex.ext1"}
7470
end subroutine
7571

7672
! test lowering of character allocatables. Focus is placed on the length handling

flang/test/Lower/character-local-variables.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
subroutine scalar_cst_len()
99
character(10) :: c
1010
! CHECK: fir.alloca !fir.char<1,10> {{{.*}}uniq_name = "_QFscalar_cst_lenEc"}
11+
print *, c
1112
end subroutine
1213

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

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

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

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

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

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

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

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

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

116126
! Test that the length of assumed length parameter is correctly deduced in lowering.
@@ -129,4 +139,5 @@ subroutine assumed_length_param(n)
129139
subroutine scalar_cst_neg_len()
130140
character(-1) :: c
131141
! CHECK: fir.alloca !fir.char<1,0> {{{.*}}uniq_name = "_QFscalar_cst_neg_lenEc"}
142+
print *, c
132143
end subroutine

0 commit comments

Comments
 (0)