xref: /llvm-project/mlir/test/Transforms/test-legalize-type-conversion.mlir (revision ea050ab1a99547294e195064bd90ca9822d292cf)
1// RUN: mlir-opt %s -test-legalize-type-conversion -allow-unregistered-dialect -split-input-file -verify-diagnostics | FileCheck %s
2
3
4func.func @test_invalid_arg_materialization(
5  // expected-error@below {{failed to legalize unresolved materialization from () to ('i16') that remained live after conversion}}
6  %arg0: i16) {
7  // expected-note@below{{see existing live user here}}
8  "foo.return"(%arg0) : (i16) -> ()
9}
10
11// -----
12
13// CHECK-LABEL: func @test_valid_arg_materialization
14func.func @test_valid_arg_materialization(%arg0: i64) {
15  // CHECK: %[[ARG:.*]] = "test.type_producer"
16  // CHECK: "foo.return"(%[[ARG]]) : (i64)
17
18  "foo.return"(%arg0) : (i64) -> ()
19}
20
21// -----
22
23func.func @test_invalid_result_materialization() {
24  // expected-error@below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
25  %result = "test.type_producer"() : () -> f16
26  // expected-note@below{{see existing live user here}}
27  "foo.return"(%result) : (f16) -> ()
28}
29
30// -----
31
32func.func @test_invalid_result_materialization() {
33  // expected-error@below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
34  %result = "test.type_producer"() : () -> f16
35  // expected-note@below{{see existing live user here}}
36  "foo.return"(%result) : (f16) -> ()
37}
38
39// -----
40
41// CHECK-LABEL: @test_transitive_use_materialization
42func.func @test_transitive_use_materialization() {
43  // CHECK: %[[V:.*]] = "test.type_producer"() : () -> f64
44  // CHECK: %[[C:.*]] = "test.cast"(%[[V]]) : (f64) -> f32
45  %result = "test.another_type_producer"() : () -> f32
46  // CHECK: "foo.return"(%[[C]])
47  "foo.return"(%result) : (f32) -> ()
48}
49
50// -----
51
52func.func @test_transitive_use_invalid_materialization() {
53  // expected-error@below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
54  %result = "test.another_type_producer"() : () -> f16
55  // expected-note@below{{see existing live user here}}
56  "foo.return"(%result) : (f16) -> ()
57}
58
59// -----
60
61// CHECK-LABEL: func @test_valid_result_legalization
62func.func @test_valid_result_legalization() {
63  // CHECK: %[[RESULT:.*]] = "test.type_producer"() : () -> f64
64  // CHECK: %[[CAST:.*]] = "test.cast"(%[[RESULT]]) : (f64) -> f32
65  // CHECK: "foo.return"(%[[CAST]]) : (f32)
66
67  %result = "test.type_producer"() : () -> f32
68  "foo.return"(%result) : (f32) -> ()
69}
70
71// -----
72
73// Should not segfault here but gracefully fail.
74// CHECK-LABEL: func @test_signature_conversion_undo
75func.func @test_signature_conversion_undo() {
76  // CHECK: test.signature_conversion_undo
77  "test.signature_conversion_undo"() ({
78  // CHECK: ^{{.*}}(%{{.*}}: f32):
79  ^bb0(%arg0: f32):
80    "test.type_consumer"(%arg0) : (f32) -> ()
81    "test.return"(%arg0) : (f32) -> ()
82  }) : () -> ()
83  return
84}
85
86// -----
87
88// Should not segfault here but gracefully fail.
89// CHECK-LABEL: func @test_block_argument_not_converted
90func.func @test_block_argument_not_converted() {
91  "test.unsupported_block_arg_type"() ({
92    // NOTE: The test pass does not convert `index` types.
93    // CHECK: ^bb0({{.*}}: index):
94    ^bb0(%0 : index):
95      "test.return"(%0) : (index) -> ()
96  }) : () -> ()
97  return
98}
99
100// -----
101
102// Make sure argument type changes aren't implicitly forwarded.
103func.func @test_signature_conversion_no_converter() {
104  "test.signature_conversion_no_converter"() ({
105  // expected-error@below {{failed to legalize unresolved materialization from ('f64') to ('f32') that remained live after conversion}}
106  ^bb0(%arg0: f32):
107    "test.type_consumer"(%arg0) : (f32) -> ()
108    // expected-note@below{{see existing live user here}}
109    "test.return"(%arg0) : (f32) -> ()
110  }) : () -> ()
111  return
112}
113
114// -----
115
116// CHECK-LABEL: @recursive_type_conversion
117func.func @recursive_type_conversion() {
118  // CHECK:  !test.test_rec<outer_converted_type, smpla>
119  "test.type_producer"() : () -> !test.test_rec<something, test_rec<something>>
120  return
121}
122
123// -----
124
125// CHECK-LABEL: @unsupported_func_op_interface
126llvm.func @unsupported_func_op_interface() {
127  // CHECK: llvm.return
128  llvm.return
129}
130
131// -----
132
133// CHECK-LABEL: func @test_signature_conversion_no_converter()
134func.func @test_signature_conversion_no_converter() {
135  // CHECK: "test.signature_conversion_no_converter"() ({
136  // CHECK: ^{{.*}}(%[[arg0:.*]]: f64):
137  "test.signature_conversion_no_converter"() ({
138  ^bb0(%arg0: f32):
139    // CHECK: "test.legal_op_d"(%[[arg0]]) : (f64) -> ()
140    "test.replace_with_legal_op"(%arg0) : (f32) -> ()
141    "test.return"() : () -> ()
142  }) : () -> ()
143  return
144}
145