[DebugInfo][RemoveDIs] Emulate inserting insts in dbg.value sequences (#73350)
[llvm-project.git] / flang / test / Lower / mixed_loops.f90
blob1aa0225129bed6277364a0cfcc1e179598af287b
1 ! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s
4 ! Test while loop inside do loop.
5 ! CHECK-LABEL: while_inside_do_loop
6 subroutine while_inside_do_loop
7 ! CHECK-DAG: %[[T_REF:.*]] = fir.alloca i32
8 ! CHECK-DAG: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFwhile_inside_do_loopEi"}
9 ! CHECK-DAG: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFwhile_inside_do_loopEj"}
10 integer :: i, j
12 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : i32
13 ! CHECK-DAG: %[[C8:.*]] = arith.constant 8 : i32
14 ! CHECK-DAG: %[[C13:.*]] = arith.constant 13 : i32
15 ! CHECK: %[[DIFF:.*]] = arith.subi %[[C13]], %[[C8]] : i32
16 ! CHECK: %[[RANGE:.*]] = arith.addi %[[DIFF]], %[[C1]] : i32
17 ! CHECK: %[[HIGH:.*]] = arith.divsi %[[RANGE]], %[[C1]] : i32
18 ! CHECK: fir.store %[[HIGH]] to %[[T_REF]] : !fir.ref<i32>
19 ! CHECK: fir.store %[[C8]] to %[[I_REF]] : !fir.ref<i32>
21 ! CHECK: br ^[[HDR1:.*]]
22 ! CHECK: ^[[HDR1]]: // 2 preds: ^{{.*}}, ^[[EXIT2:.*]]
23 ! CHECK-DAG: %[[T:.*]] = fir.load %[[T_REF]] : !fir.ref<i32>
24 ! CHECK-DAG: %[[C0:.*]] = arith.constant 0 : i32
25 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[T]], %[[C0]] : i32
26 ! CHECK: cond_br %[[COND]], ^[[BODY1:.*]], ^[[EXIT1:.*]]
27 do i=8,13
28 ! CHECK: ^[[BODY1]]: // pred: ^[[HDR1]]
29 ! CHECK: %[[C3:.*]] = arith.constant 3 : i32
30 ! CHECK: fir.store %[[C3]] to %[[J_REF]] : !fir.ref<i32>
31 j=3
33 ! CHECK: br ^[[HDR2:.*]]
34 ! CHECK: ^[[HDR2]]: // 2 preds: ^[[BODY1]], ^[[BODY2:.*]]
35 ! CHECK-DAG: %[[J:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
36 ! CHECK-DAG: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
37 ! CHECK: %[[COND2:.*]] = arith.cmpi slt, %[[J]], %[[I]] : i32
38 ! CHECK: cond_br %[[COND2]], ^[[BODY2]], ^[[EXIT2]]
39 do while (j .lt. i)
40 ! CHECK: ^[[BODY2]]: // pred: ^[[HDR2]]
41 ! CHECK-DAG: %[[J2:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
42 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
43 ! CHECK: %[[INC2:.*]] = arith.muli %[[C2]], %[[J2]] : i32
44 ! CHECK: fir.store %[[INC2]] to %[[J_REF]] : !fir.ref<i32>
45 j=j*2
46 ! CHECK: br ^[[HDR2]]
47 end do
49 ! CHECK: ^[[EXIT2]]: // pred: ^[[HDR2]]
50 ! CHECK-DAG: %[[T2:.*]] = fir.load %[[T_REF]] : !fir.ref<i32>
51 ! CHECK-DAG: %[[C1_AGAIN:.*]] = arith.constant 1 : i32
52 ! CHECK: %[[TDEC:.*]] = arith.subi %[[T2]], %[[C1_AGAIN]] : i32
53 ! CHECK: fir.store %[[TDEC]] to %[[T_REF]]
54 ! CHECK: %[[I3:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
55 ! CHECK: %[[C1_2:.*]] = arith.constant 1 : i32
56 ! CHECK: %[[IINC:.*]] = arith.addi %[[I3]], %[[C1_2]] : i32
57 ! CHECK: fir.store %[[IINC]] to %[[I_REF]] : !fir.ref<i32>
58 ! CHECK: br ^[[HDR1]]
59 end do
61 ! CHECK: ^[[EXIT1]]: // pred: ^[[HDR1]]
62 ! CHECK: %[[IPRINT:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
63 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[IPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
64 ! CHECK: %[[JPRINT:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
65 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[JPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
66 print *, i, j
67 end subroutine
69 ! Test do loop inside while loop.
70 ! CHECK-LABEL: do_inside_while_loop
71 subroutine do_inside_while_loop
72 ! CHECK-DAG: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFdo_inside_while_loopEi"}
73 ! CHECK-DAG: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFdo_inside_while_loopEj"}
74 integer :: i, j
76 ! CHECK: %[[C3:.*]] = arith.constant 3 : i32
77 ! CHECK: fir.store %[[C3]] to %[[J_REF]] : !fir.ref<i32>
78 j=3
80 ! CHECK: br ^[[HDR1:.*]]
81 ! CHECK: ^[[HDR1]]: // 2 preds: ^{{.*}}, ^[[BODY1:.*]]
82 ! CHECK-DAG: %[[J:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
83 ! CHECK-DAG: %[[UL:.*]] = arith.constant 21 : i32
84 ! CHECK: %[[COND:.*]] = arith.cmpi slt, %[[J]], %[[UL]] : i32
85 ! CHECK: cond_br %[[COND]], ^[[BODY1]], ^[[EXIT1:.*]]
86 do while (j .lt. 21)
87 ! CHECK: ^[[BODY1]]: // pred: ^[[HDR1]]
89 ! CHECK-DAG: %[[C8_I32:.*]] = arith.constant 8 : i32
90 ! CHECK-DAG: %[[C8:.*]] = fir.convert %[[C8_I32]] : (i32) -> index
91 ! CHECK-DAG: %[[C13_I32:.*]] = arith.constant 13 : i32
92 ! CHECK-DAG: %[[C13:.*]] = fir.convert %[[C13_I32]] : (i32) -> index
93 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index
94 ! CHECK: %[[I_LB:.*]] = fir.convert %[[C8]] : (index) -> i32
95 ! CHECK: %[[RESULT:.*]]:2 = fir.do_loop %[[IDX:[^ ]*]] =
96 ! CHECK-SAME: %[[C8]] to %[[C13]] step %[[C1]]
97 ! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
98 ! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
99 ! CHECK-DAG: %[[J2:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
100 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
101 ! CHECK: %[[JINC:.*]] = arith.muli %[[C2]], %[[J2]] : i32
102 ! CHECK: fir.store %[[JINC]] to %[[J_REF]] : !fir.ref<i32>
103 ! CHECK: %[[IINC:.*]] = arith.addi %[[IDX]], %[[C1]] : index
104 ! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
105 ! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
106 ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
107 ! CHECK: fir.result %[[IINC]], %[[I_IVINC]] : index, i32
108 do i=8,13
109 j=j*2
111 ! CHECK: fir.store %[[RESULT]]#1 to %[[I_REF]] : !fir.ref<i32>
112 end do
114 ! CHECK: br ^[[HDR1]]
115 end do
117 ! CHECK: ^[[EXIT1]]: // pred: ^[[HDR1]]
118 ! CHECK: %[[IPRINT:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
119 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[IPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
120 ! CHECK: %[[JPRINT:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
121 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[JPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
122 print *, i, j
123 end subroutine