IR: de-duplicate two CmpInst routines (NFC) (#116866)
[llvm-project.git] / flang / test / Lower / block.f90
blobd2bc90ef6c671c4394aaf471df522dd59fcd4d88
1 ! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QQmain
4 program bb ! block stack management and exits
5 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {adapt.valuebyref}
6 ! CHECK: %[[V_1:[0-9]+]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
7 integer :: i, j
8 ! CHECK: fir.store %c0{{.*}} to %[[V_1]] : !fir.ref<i32>
9 i = 0
10 ! CHECK: %[[V_3:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
11 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
12 ! CHECK: br ^bb1
13 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb16
14 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb17
15 ! CHECK: ^bb2: // pred: ^bb1
16 ! CHECK: %[[V_11:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
17 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
18 ! CHECK: cond_br %{{.*}}, ^bb3, ^bb4
19 ! CHECK: ^bb3: // pred: ^bb2
20 ! CHECK: br ^bb10
21 ! CHECK: ^bb4: // pred: ^bb2
22 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
23 ! CHECK: cond_br %{{.*}}, ^bb5, ^bb6
24 ! CHECK: ^bb5: // pred: ^bb4
25 ! CHECK: br ^bb14
26 ! CHECK: ^bb6: // pred: ^bb4
27 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
28 ! CHECK: cond_br %{{.*}}, ^bb7, ^bb8
29 ! CHECK: ^bb7: // pred: ^bb6
30 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
31 ! CHECK: br ^bb15
32 ! CHECK: ^bb8: // pred: ^bb6
33 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
34 ! CHECK: cond_br %{{.*}}, ^bb9, ^bb10
35 ! CHECK: ^bb9: // pred: ^bb8
36 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
37 ! CHECK: br ^bb16
38 ! CHECK: ^bb10: // 2 preds: ^bb3, ^bb8
39 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
40 ! CHECK: cond_br %{{.*}}, ^bb11, ^bb12
41 ! CHECK: ^bb11: // pred: ^bb10
42 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
43 ! CHECK: br ^bb18
44 ! CHECK: ^bb12: // pred: ^bb10
45 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
46 ! CHECK: cond_br %{{.*}}, ^bb13, ^bb14
47 ! CHECK: ^bb13: // pred: ^bb12
48 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
49 ! CHECK: llvm.intr.stackrestore %[[V_3]] : !llvm.ptr
50 ! CHECK: br ^bb19
51 ! CHECK: ^bb14: // 2 preds: ^bb5, ^bb12
52 ! CHECK: llvm.intr.stackrestore %[[V_11]] : !llvm.ptr
53 ! CHECK: br ^bb15
54 ! CHECK: ^bb15: // 2 preds: ^bb7, ^bb14
55 ! CHECK: br ^bb16
56 ! CHECK: ^bb16: // 2 preds: ^bb9, ^bb15
57 ! CHECK: br ^bb1
58 ! CHECK: ^bb17: // pred: ^bb1
59 ! CHECK: fir.store %{{.*}} to %[[V_1]] : !fir.ref<i32>
60 ! CHECK: cf.br ^bb18
61 ! CHECK: ^bb18: // 2 preds: ^bb11, ^bb17
62 ! CHECK: llvm.intr.stackrestore %[[V_3]] : !llvm.ptr
63 ! CHECK: br ^bb19
64 ! CHECK: ^bb19: // 2 preds: ^bb13, ^bb18
65 block
66 i = i + 1 ! 1 increment
67 do j = 1, 5
68 block
69 i = i + 1; if (j == 1) goto 1 ! inner block - 5 increments, 1 goto
70 i = i + 1; if (j == 2) goto 2 ! inner block - 4 increments, 1 goto
71 i = i + 1; if (j == 3) goto 10 ! outer block - 3 increments, 1 goto
72 i = i + 1; if (j == 4) goto 11 ! outer block - 2 increments, 1 goto
73 1 i = i + 1; if (j == 5) goto 12 ! outer block - 2 increments, 1 goto
74 i = i + 1; if (j == 6) goto 100 ! program - 1 increment
75 2 end block
76 10 i = i + 1 ! 3 increments
77 11 end do
78 i = i + 1 ! 0 increments
79 12 end block
80 100 print*, i ! expect 21
82 ! CHECK: %[[V_51:[0-9]+]] = llvm.intr.stacksave : !llvm.ptr
83 ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
84 ! CHECK: fir.call @ss(%[[V_0]]) proc_attrs<bind_c> fastmath<contract> : (!fir.ref<i32>) -> ()
85 ! CHECK: llvm.intr.stackrestore %[[V_51]] : !llvm.ptr
86 block
87 interface
88 subroutine ss(n) bind(c)
89 integer :: n
90 end subroutine
91 end interface
92 call ss(5)
93 end block
94 end
96 subroutine ss(n) bind(c)
97 print*, n
98 end subroutine