• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt -allow-unregistered-dialect -test-scf-if-utils -split-input-file %s | FileCheck %s
2
3// -----
4
5//      CHECK: func @outlined_then0(%{{.*}}: i1, %{{.*}}: memref<?xf32>) -> i8 {
6// CHECK-NEXT:   %{{.*}} = "some_op"(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> i8
7// CHECK-NEXT:   return %{{.*}} : i8
8// CHECK-NEXT: }
9//      CHECK: func @outlined_else0(%{{.*}}: i8) -> i8 {
10// CHECK-NEXT:   return %{{.*}}0 : i8
11// CHECK-NEXT: }
12//      CHECK: func @outline_if_else(
13// CHECK-NEXT:   %{{.*}} = scf.if %{{.*}} -> (i8) {
14// CHECK-NEXT:     %{{.*}} = call @outlined_then0(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> i8
15// CHECK-NEXT:     scf.yield %{{.*}} : i8
16// CHECK-NEXT:   } else {
17// CHECK-NEXT:     %{{.*}} = call @outlined_else0(%{{.*}}) : (i8) -> i8
18// CHECK-NEXT:     scf.yield %{{.*}} : i8
19// CHECK-NEXT:   }
20// CHECK-NEXT:   return
21// CHECK-NEXT: }
22func @outline_if_else(%cond: i1, %a: index, %b: memref<?xf32>, %c: i8) {
23  %r = scf.if %cond -> (i8) {
24    %r = "some_op"(%cond, %b) : (i1, memref<?xf32>) -> (i8)
25    scf.yield %r : i8
26  } else {
27    scf.yield %c : i8
28  }
29  return
30}
31
32// -----
33
34//      CHECK: func @outlined_then0(%{{.*}}: i1, %{{.*}}: memref<?xf32>) {
35// CHECK-NEXT:   "some_op"(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> ()
36// CHECK-NEXT:   return
37// CHECK-NEXT: }
38//      CHECK: func @outline_if(
39// CHECK-NEXT:   scf.if %{{.*}} {
40// CHECK-NEXT:     call @outlined_then0(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> ()
41// CHECK-NEXT:   }
42// CHECK-NEXT:   return
43// CHECK-NEXT: }
44func @outline_if(%cond: i1, %a: index, %b: memref<?xf32>, %c: i8) {
45  scf.if %cond {
46    "some_op"(%cond, %b) : (i1, memref<?xf32>) -> ()
47    scf.yield
48  }
49  return
50}
51
52// -----
53
54//      CHECK: func @outlined_then0() {
55// CHECK-NEXT:   return
56// CHECK-NEXT: }
57//      CHECK: func @outlined_else0(%{{.*}}: i1, %{{.*}}: memref<?xf32>) {
58// CHECK-NEXT:   "some_op"(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> ()
59// CHECK-NEXT:   return
60// CHECK-NEXT: }
61//      CHECK: func @outline_empty_if_else(
62// CHECK-NEXT:   scf.if %{{.*}} {
63// CHECK-NEXT:     call @outlined_then0() : () -> ()
64// CHECK-NEXT:   } else {
65// CHECK-NEXT:     call @outlined_else0(%{{.*}}, %{{.*}}) : (i1, memref<?xf32>) -> ()
66// CHECK-NEXT:   }
67// CHECK-NEXT:   return
68// CHECK-NEXT: }
69func @outline_empty_if_else(%cond: i1, %a: index, %b: memref<?xf32>, %c: i8) {
70  scf.if %cond {
71  } else {
72    "some_op"(%cond, %b) : (i1, memref<?xf32>) -> ()
73  }
74  return
75}
76