1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s
// Test case: Simple case of deleting a dead pure op.
// CHECK: func @f(%arg0: f32) {
// CHECK-NEXT: return
func @f(%arg0: f32) {
%0 = "std.addf"(%arg0, %arg0) : (f32, f32) -> f32
return
}
// -----
// Test case: Simple case of deleting a block argument.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: "test.br"()[^bb1]
// CHECK-NEXT: ^bb1:
// CHECK-NEXT: return
func @f(%arg0: f32) {
"test.br"(%arg0)[^succ] : (f32) -> ()
^succ(%0: f32):
return
}
// -----
// Test case: Deleting recursively dead block arguments.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: br ^bb1
// CHECK-NEXT: ^bb1:
// CHECK-NEXT: br ^bb1
func @f(%arg0: f32) {
br ^loop(%arg0: f32)
^loop(%loop: f32):
br ^loop(%loop: f32)
}
// -----
// Test case: Deleting recursively dead block arguments with pure ops in between.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: br ^bb1
// CHECK-NEXT: ^bb1:
// CHECK-NEXT: br ^bb1
func @f(%arg0: f32) {
br ^loop(%arg0: f32)
^loop(%0: f32):
%1 = "std.exp"(%0) : (f32) -> f32
br ^loop(%1: f32)
}
// -----
// Test case: Delete block arguments for cond_br.
// CHECK: func @f(%arg0: f32, %arg1: i1)
// CHECK-NEXT: return
func @f(%arg0: f32, %pred: i1) {
%exp = "std.exp"(%arg0) : (f32) -> f32
cond_br %pred, ^true(%exp: f32), ^false(%exp: f32)
^true(%0: f32):
return
^false(%1: f32):
return
}
// -----
// Test case: Recursively DCE into enclosed regions.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: func @g(%arg1: f32)
// CHECK-NEXT: return
func @f(%arg0: f32) {
func @g(%arg1: f32) {
%0 = "std.addf"(%arg1, %arg1) : (f32, f32) -> f32
return
}
return
}
// -----
// Test case: Don't delete pure ops that feed into returns.
// CHECK: func @f(%arg0: f32) -> f32
// CHECK-NEXT: [[VAL0:%.+]] = addf %arg0, %arg0 : f32
// CHECK-NEXT: return [[VAL0]] : f32
func @f(%arg0: f32) -> f32 {
%0 = "std.addf"(%arg0, %arg0) : (f32, f32) -> f32
return %0 : f32
}
// -----
// Test case: Don't delete potentially side-effecting ops.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: "foo.print"(%arg0) : (f32) -> ()
// CHECK-NEXT: return
func @f(%arg0: f32) {
"foo.print"(%arg0) : (f32) -> ()
return
}
// -----
// Test case: Uses in nested regions are deleted correctly.
// CHECK: func @f(%arg0: f32)
// CHECK-NEXT: "foo.has_region"
// CHECK-NEXT: "foo.return"
func @f(%arg0: f32) {
%0 = "std.exp"(%arg0) : (f32) -> f32
"foo.has_region"() ({
%1 = "std.exp"(%0) : (f32) -> f32
"foo.return"() : () -> ()
}) : () -> ()
return
}
// -----
// Test case: Test the mechanics of deleting multiple block arguments.
// CHECK: func @f(%arg0: tensor<1xf32>, %arg1: tensor<2xf32>, %arg2: tensor<3xf32>, %arg3: tensor<4xf32>, %arg4: tensor<5xf32>)
// CHECK-NEXT: "test.br"(%arg1, %arg3)[^bb1] : (tensor<2xf32>, tensor<4xf32>)
// CHECK-NEXT: ^bb1([[VAL0:%.+]]: tensor<2xf32>, [[VAL1:%.+]]: tensor<4xf32>):
// CHECK-NEXT: "foo.print"([[VAL0]])
// CHECK-NEXT: "foo.print"([[VAL1]])
// CHECK-NEXT: return
func @f(
%arg0: tensor<1xf32>,
%arg1: tensor<2xf32>,
%arg2: tensor<3xf32>,
%arg3: tensor<4xf32>,
%arg4: tensor<5xf32>) {
"test.br"(%arg0, %arg1, %arg2, %arg3, %arg4)[^succ] : (tensor<1xf32>, tensor<2xf32>, tensor<3xf32>, tensor<4xf32>, tensor<5xf32>) -> ()
^succ(%t1: tensor<1xf32>, %t2: tensor<2xf32>, %t3: tensor<3xf32>, %t4: tensor<4xf32>, %t5: tensor<5xf32>):
"foo.print"(%t2) : (tensor<2xf32>) -> ()
"foo.print"(%t4) : (tensor<4xf32>) -> ()
return
}
|