2020-03-30 06:35:38 +08:00
|
|
|
// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-legalize-patterns -verify-diagnostics %s | FileCheck %s
|
2019-06-12 06:38:13 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: verifyDirectPattern
|
|
|
|
func @verifyDirectPattern() -> i32 {
|
2019-06-26 10:06:06 +08:00
|
|
|
// CHECK-NEXT: "test.legal_op_a"() {status = "Success"}
|
2019-06-12 06:38:13 +08:00
|
|
|
%result = "test.illegal_op_a"() : () -> (i32)
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-06-12 06:38:13 +08:00
|
|
|
return %result : i32
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: verifyLargerBenefit
|
|
|
|
func @verifyLargerBenefit() -> i32 {
|
2019-06-26 10:06:06 +08:00
|
|
|
// CHECK-NEXT: "test.legal_op_a"() {status = "Success"}
|
2019-06-12 06:38:13 +08:00
|
|
|
%result = "test.illegal_op_c"() : () -> (i32)
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-06-12 06:38:13 +08:00
|
|
|
return %result : i32
|
|
|
|
}
|
2019-06-20 04:58:31 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @remap_input_1_to_0()
|
|
|
|
func @remap_input_1_to_0(i16)
|
|
|
|
|
2019-06-29 02:28:30 +08:00
|
|
|
// CHECK-LABEL: func @remap_input_1_to_1(%arg0: f64)
|
|
|
|
func @remap_input_1_to_1(%arg0: i64) {
|
|
|
|
// CHECK-NEXT: "test.valid"{{.*}} : (f64)
|
|
|
|
"test.invalid"(%arg0) : (i64) -> ()
|
2019-06-20 04:58:31 +08:00
|
|
|
}
|
|
|
|
|
2020-03-19 10:58:04 +08:00
|
|
|
// CHECK-LABEL: func @remap_call_1_to_1(%arg0: f64)
|
|
|
|
func @remap_call_1_to_1(%arg0: i64) {
|
|
|
|
// CHECK-NEXT: call @remap_input_1_to_1(%arg0) : (f64) -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.call' is not legalizable}}
|
2020-03-19 10:58:04 +08:00
|
|
|
call @remap_input_1_to_1(%arg0) : (i64) -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2020-03-19 10:58:04 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-02 01:12:33 +08:00
|
|
|
// CHECK-LABEL: func @remap_input_1_to_N({{.*}}f16, {{.*}}f16)
|
2019-06-22 00:29:46 +08:00
|
|
|
func @remap_input_1_to_N(%arg0: f32) -> f32 {
|
2019-07-02 01:12:33 +08:00
|
|
|
// CHECK-NEXT: "test.return"{{.*}} : (f16, f16) -> ()
|
|
|
|
"test.return"(%arg0) : (f32) -> ()
|
2019-06-22 00:29:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @remap_input_1_to_N_remaining_use(%arg0: f16, %arg1: f16)
|
|
|
|
func @remap_input_1_to_N_remaining_use(%arg0: f32) {
|
|
|
|
// CHECK-NEXT: [[CAST:%.*]] = "test.cast"(%arg0, %arg1) : (f16, f16) -> f32
|
|
|
|
// CHECK-NEXT: "work"([[CAST]]) : (f32) -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'work' is not legalizable}}
|
2019-06-22 00:29:46 +08:00
|
|
|
"work"(%arg0) : (f32) -> ()
|
|
|
|
}
|
|
|
|
|
2020-06-02 19:24:04 +08:00
|
|
|
// CHECK-LABEL: func @remap_materialize_1_to_1(%{{.*}}: i43)
|
|
|
|
func @remap_materialize_1_to_1(%arg0: i42) {
|
|
|
|
// CHECK: %[[V:.*]] = "test.cast"(%arg0) : (i43) -> i42
|
|
|
|
// CHECK: "test.return"(%[[V]])
|
|
|
|
"test.return"(%arg0) : (i42) -> ()
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:52:53 +08:00
|
|
|
// CHECK-LABEL: func @remap_input_to_self
|
|
|
|
func @remap_input_to_self(%arg0: index) {
|
|
|
|
// CHECK-NOT: test.cast
|
|
|
|
// CHECK: "work"
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'work' is not legalizable}}
|
2019-07-02 00:52:53 +08:00
|
|
|
"work"(%arg0) : (index) -> ()
|
|
|
|
}
|
|
|
|
|
2019-06-20 04:58:31 +08:00
|
|
|
// CHECK-LABEL: func @remap_multi(%arg0: f64, %arg1: f64) -> (f64, f64)
|
|
|
|
func @remap_multi(%arg0: i64, %unused: i16, %arg1: i64) -> (i64, i64) {
|
2019-06-29 02:28:30 +08:00
|
|
|
// CHECK-NEXT: "test.valid"{{.*}} : (f64, f64)
|
|
|
|
"test.invalid"(%arg0, %arg1) : (i64, i64) -> ()
|
2019-06-20 04:58:31 +08:00
|
|
|
}
|
|
|
|
|
2019-07-21 10:05:41 +08:00
|
|
|
// CHECK-LABEL: func @no_remap_nested
|
|
|
|
func @no_remap_nested() {
|
2019-06-20 04:58:31 +08:00
|
|
|
// CHECK-NEXT: "foo.region"
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'foo.region' is not legalizable}}
|
2019-06-20 04:58:31 +08:00
|
|
|
"foo.region"() ({
|
2019-07-21 10:05:41 +08:00
|
|
|
// CHECK-NEXT: ^bb0(%{{.*}}: i64, %{{.*}}: i16, %{{.*}}: i64):
|
2019-07-10 01:40:29 +08:00
|
|
|
^bb0(%i0: i64, %unused: i16, %i1: i64):
|
2019-07-21 10:05:41 +08:00
|
|
|
// CHECK-NEXT: "test.valid"{{.*}} : (i64, i64)
|
2019-06-29 02:28:30 +08:00
|
|
|
"test.invalid"(%i0, %i1) : (i64, i64) -> ()
|
2019-06-20 04:58:31 +08:00
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-06-20 04:58:31 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @remap_moved_region_args
|
|
|
|
func @remap_moved_region_args() {
|
|
|
|
// CHECK-NEXT: return
|
2019-06-22 00:29:46 +08:00
|
|
|
// CHECK-NEXT: ^bb1(%{{.*}}: f64, %{{.*}}: f64, %{{.*}}: f16, %{{.*}}: f16):
|
|
|
|
// CHECK-NEXT: "test.cast"{{.*}} : (f16, f16) -> f32
|
2019-06-29 02:28:30 +08:00
|
|
|
// CHECK-NEXT: "test.valid"{{.*}} : (f64, f64, f32)
|
2019-06-20 04:58:31 +08:00
|
|
|
"test.region"() ({
|
2019-06-22 00:29:46 +08:00
|
|
|
^bb1(%i0: i64, %unused: i16, %i1: i64, %2: f32):
|
2019-06-29 02:28:30 +08:00
|
|
|
"test.invalid"(%i0, %i1, %2) : (i64, i64, f32) -> ()
|
2019-06-20 04:58:31 +08:00
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-06-20 04:58:31 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-09 06:44:34 +08:00
|
|
|
// CHECK-LABEL: func @remap_cloned_region_args
|
|
|
|
func @remap_cloned_region_args() {
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: ^bb1(%{{.*}}: f64, %{{.*}}: f64, %{{.*}}: f16, %{{.*}}: f16):
|
|
|
|
// CHECK-NEXT: "test.cast"{{.*}} : (f16, f16) -> f32
|
|
|
|
// CHECK-NEXT: "test.valid"{{.*}} : (f64, f64, f32)
|
|
|
|
"test.region"() ({
|
|
|
|
^bb1(%i0: i64, %unused: i16, %i1: i64, %2: f32):
|
|
|
|
"test.invalid"(%i0, %i1, %2) : (i64, i64, f32) -> ()
|
|
|
|
}) {legalizer.should_clone} : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-10-09 06:44:34 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-20 04:58:31 +08:00
|
|
|
// CHECK-LABEL: func @remap_drop_region
|
|
|
|
func @remap_drop_region() {
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-11-14 02:27:21 +08:00
|
|
|
"test.drop_region_op"() ({
|
2019-06-22 00:29:46 +08:00
|
|
|
^bb1(%i0: i64, %unused: i16, %i1: i64, %2: f32):
|
2019-06-29 02:28:30 +08:00
|
|
|
"test.invalid"(%i0, %i1, %2) : (i64, i64, f32) -> ()
|
2019-06-20 04:58:31 +08:00
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-06-20 04:58:31 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-29 02:28:30 +08:00
|
|
|
// CHECK-LABEL: func @dropped_input_in_use
|
2019-06-20 04:58:31 +08:00
|
|
|
func @dropped_input_in_use(%arg: i16, %arg2: i64) {
|
2019-06-29 02:28:30 +08:00
|
|
|
// CHECK-NEXT: "test.cast"{{.*}} : () -> i16
|
|
|
|
// CHECK-NEXT: "work"{{.*}} : (i16)
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'work' is not legalizable}}
|
2019-06-20 04:58:31 +08:00
|
|
|
"work"(%arg) : (i16) -> ()
|
|
|
|
}
|
2019-07-15 04:29:46 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @up_to_date_replacement
|
|
|
|
func @up_to_date_replacement(%arg: i8) -> i8 {
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
%repl_1 = "test.rewrite"(%arg) : (i8) -> i8
|
|
|
|
%repl_2 = "test.rewrite"(%repl_1) : (i8) -> i8
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-07-15 04:29:46 +08:00
|
|
|
return %repl_2 : i8
|
|
|
|
}
|
2019-07-18 00:26:57 +08:00
|
|
|
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-LABEL: func @remove_foldable_op
|
|
|
|
// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32)
|
|
|
|
func @remove_foldable_op(%arg0 : i32) -> (i32) {
|
|
|
|
// CHECK-NEXT: return %[[ARG_0]]
|
|
|
|
%0 = "test.op_with_region_fold"(%arg0) ({
|
|
|
|
"foo.op_with_region_terminator"() : () -> ()
|
|
|
|
}) : (i32) -> (i32)
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2019-12-14 04:21:42 +08:00
|
|
|
return %0 : i32
|
|
|
|
}
|
|
|
|
|
2020-04-04 01:53:13 +08:00
|
|
|
// CHECK-LABEL: @create_block
|
|
|
|
func @create_block() {
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'test.container' is not legalizable}}
|
2020-04-04 01:53:13 +08:00
|
|
|
"test.container"() ({
|
|
|
|
// Check that we created a block with arguments.
|
|
|
|
// CHECK-NOT: test.create_block
|
|
|
|
// CHECK: ^{{.*}}(%{{.*}}: i32, %{{.*}}: i32):
|
|
|
|
// CHECK: test.finish
|
|
|
|
"test.create_block"() : () -> ()
|
|
|
|
"test.finish"() : () -> ()
|
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2020-04-04 01:53:13 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-10 03:38:52 +08:00
|
|
|
// CHECK-LABEL: @bounded_recursion
|
|
|
|
func @bounded_recursion() {
|
|
|
|
// CHECK: test.recursive_rewrite 0
|
|
|
|
test.recursive_rewrite 3
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2020-04-10 03:38:52 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-18 00:26:57 +08:00
|
|
|
// -----
|
|
|
|
|
|
|
|
func @fail_to_convert_illegal_op() -> i32 {
|
|
|
|
// expected-error@+1 {{failed to legalize operation 'test.illegal_op_f'}}
|
|
|
|
%result = "test.illegal_op_f"() : () -> (i32)
|
|
|
|
return %result : i32
|
|
|
|
}
|
2019-07-18 05:45:53 +08:00
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
func @fail_to_convert_illegal_op_in_region() {
|
|
|
|
// expected-error@+1 {{failed to legalize operation 'test.region_builder'}}
|
|
|
|
"test.region_builder"() : () -> ()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// Check that the entry block arguments of a region are untouched in the case
|
|
|
|
// of failure.
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @fail_to_convert_region
|
|
|
|
func @fail_to_convert_region() {
|
2019-10-11 03:01:45 +08:00
|
|
|
// CHECK-NEXT: "test.region"
|
2019-07-18 05:45:53 +08:00
|
|
|
// CHECK-NEXT: ^bb{{.*}}(%{{.*}}: i64):
|
2019-10-11 03:01:45 +08:00
|
|
|
"test.region"() ({
|
2019-07-18 05:45:53 +08:00
|
|
|
^bb1(%i0: i64):
|
|
|
|
// expected-error@+1 {{failed to legalize operation 'test.region_builder'}}
|
|
|
|
"test.region_builder"() : () -> ()
|
|
|
|
"test.valid"() : () -> ()
|
|
|
|
}) : () -> ()
|
|
|
|
return
|
|
|
|
}
|
2020-04-04 01:53:13 +08:00
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// CHECK-LABEL: @create_illegal_block
|
|
|
|
func @create_illegal_block() {
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'test.container' is not legalizable}}
|
2020-04-04 01:53:13 +08:00
|
|
|
"test.container"() ({
|
|
|
|
// Check that we can undo block creation, i.e. that the block was removed.
|
|
|
|
// CHECK: test.create_illegal_block
|
|
|
|
// CHECK-NOT: ^{{.*}}(%{{.*}}: i32, %{{.*}}: i32):
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'test.create_illegal_block' is not legalizable}}
|
2020-04-04 01:53:13 +08:00
|
|
|
"test.create_illegal_block"() : () -> ()
|
|
|
|
"test.finish"() : () -> ()
|
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2020-04-04 01:53:13 +08:00
|
|
|
return
|
|
|
|
}
|
2020-04-25 03:25:05 +08:00
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// CHECK-LABEL: @undo_block_arg_replace
|
|
|
|
func @undo_block_arg_replace() {
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'test.undo_block_arg_replace' is not legalizable}}
|
2020-04-25 03:25:05 +08:00
|
|
|
"test.undo_block_arg_replace"() ({
|
|
|
|
^bb0(%arg0: i32):
|
|
|
|
// CHECK: ^bb0(%[[ARG:.*]]: i32):
|
|
|
|
// CHECK-NEXT: "test.return"(%[[ARG]]) : (i32)
|
|
|
|
|
|
|
|
"test.return"(%arg0) : (i32) -> ()
|
|
|
|
}) : () -> ()
|
2020-05-01 00:47:19 +08:00
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
2020-04-25 03:25:05 +08:00
|
|
|
return
|
|
|
|
}
|
2020-05-20 21:59:54 +08:00
|
|
|
|
|
|
|
// -----
|
|
|
|
|
2020-05-20 22:00:27 +08:00
|
|
|
// The op in this function is rewritten to itself (and thus remains illegal) by
|
|
|
|
// a pattern that removes its second block after adding an operation into it.
|
|
|
|
// Check that we can undo block removal succesfully.
|
|
|
|
// CHECK-LABEL: @undo_block_erase
|
|
|
|
func @undo_block_erase() {
|
|
|
|
// CHECK: test.undo_block_erase
|
|
|
|
"test.undo_block_erase"() ({
|
|
|
|
// expected-remark@-1 {{not legalizable}}
|
|
|
|
// CHECK: "unregistered.return"()[^[[BB:.*]]]
|
|
|
|
"unregistered.return"()[^bb1] : () -> ()
|
|
|
|
// expected-remark@-1 {{not legalizable}}
|
|
|
|
// CHECK: ^[[BB]]
|
|
|
|
^bb1:
|
|
|
|
// CHECK: unregistered.return
|
|
|
|
"unregistered.return"() : () -> ()
|
|
|
|
// expected-remark@-1 {{not legalizable}}
|
|
|
|
}) : () -> ()
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
2020-05-20 21:59:54 +08:00
|
|
|
// The op in this function is attempted to be rewritten to another illegal op
|
|
|
|
// with an attached region containing an invalid terminator. The terminator is
|
|
|
|
// created before the parent op. The deletion should not crash when deleting
|
|
|
|
// created ops in the inverse order, i.e. deleting the parent op and then the
|
|
|
|
// child op.
|
|
|
|
// CHECK-LABEL: @undo_child_created_before_parent
|
|
|
|
func @undo_child_created_before_parent() {
|
|
|
|
// expected-remark@+1 {{is not legalizable}}
|
|
|
|
"test.illegal_op_with_region_anchor"() : () -> ()
|
|
|
|
// expected-remark@+1 {{op 'std.return' is not legalizable}}
|
|
|
|
return
|
|
|
|
}
|