1 // RUN: mlir-opt %s --mlir-disable-threading -test-block-is-in-loop 2>&1 | FileCheck %s
4 // Test function with only one bb
8 // CHECK: Block is not in a loop
11 // Test simple loop bb0 -> bb0
12 func.func @loopForever() {
18 // CHECK: Block is not in a loop
20 // CHECK: Block is in a loop
23 // Test bb0 -> bb1 -> bb2 -> bb1
24 func.func @loopForever2() {
32 // CHECK: Block is not in a loop
34 // CHECK: Block is in a loop
36 // CHECK: Block is in a loop
39 // Test conditional branch without loop
40 // bb0 -> bb1 -> {bb2, bb3}
41 func.func @noLoop(%arg0: i1) {
44 cf.cond_br %arg0, ^bb2, ^bb3
50 // CHECK: Block is not in a loop
51 // CHECK-NEXT: ^bb0(%arg0: i1)
52 // CHECK: Block is not in a loop
54 // CHECK: Block is not in a loop
56 // CHECK: Block is not in a loop
59 // test multiple loops
60 // bb0 -> bb1 -> bb2 -> bb3 { -> bb2} -> bb4 { -> bb1 } -> bb5
61 func.func @multipleLoops(%arg0: i1, %arg1: i1) {
68 cf.cond_br %arg0, ^bb4, ^bb2
70 cf.cond_br %arg1, ^bb1, ^bb5
74 // CHECK: Block is not in a loop
75 // CHECK-NEXT: ^bb0(%arg0: i1, %arg1: i1)
76 // CHECK: Block is in a loop
78 // CHECK: Block is in a loop
80 // CHECK: Block is in a loop
82 // CHECK: Block is in a loop
84 // CHECK: Block is not in a loop
87 // test derived from real Flang output
88 func.func @_QPblockTest0(%arg0: i1, %arg1: i1) {
90 ^bb1: // 2 preds: ^bb0, ^bb4
91 cf.cond_br %arg0, ^bb2, ^bb5
93 cf.cond_br %arg1, ^bb3, ^bb4
101 // CHECK: Block is not in a loop
102 // CHECK-NEXT: ^bb0(%arg0: i1, %arg1: i1)
103 // CHECK: Block is in a loop
105 // CHECK: Block is in a loop
107 // CHECK: Block is not in a loop
109 // CHECK: Block is in a loop
111 // CHECK: Block is not in a loop
114 // check nested blocks
115 func.func @check_alloc_in_loop(%counter : i64) {
116 cf.br ^bb1(%counter: i64)
118 %cm1 = arith.constant -1 : i64
119 %rem = arith.addi %lv, %cm1 : i64
120 %zero = arith.constant 0 : i64
121 %p = arith.cmpi eq, %rem, %zero : i64
122 cf.cond_br %p, ^bb3, ^bb2
124 scf.execute_region -> () {
125 %c1 = arith.constant 1 : i64
128 cf.br ^bb1(%rem: i64)
132 // CHECK: Block is not in a loop
133 // CHECK-NEXT: ^bb0(%arg0: i64):
134 // CHECK: Block is in a loop
135 // CHECK-NEXT: ^bb1(%0: i64)
136 // CHECK: Block is in a loop
138 // CHECK-NEXT: %c1_i64
139 // CHECK: Block is in a loop
141 // CHECK: Block is not in a loop