1 // RUN: mlir-opt %s -test-legalize-type-conversion -allow-unregistered-dialect -split-input-file -verify-diagnostics | FileCheck %s
4 func.func @test_invalid_arg_materialization(
5 // expected-error@below {{failed to legalize unresolved materialization from () to ('i16') that remained live after conversion}}
7 // expected-note@below{{see existing live user here}}
8 "foo.return"(%arg0) : (i16) -> ()
13 // CHECK-LABEL: func @test_valid_arg_materialization
14 func.func @test_valid_arg_materialization(%arg0: i64) {
15 // CHECK: %[[ARG:.*]] = "test.type_producer"
16 // CHECK: "foo.return"(%[[ARG]]) : (i64)
18 "foo.return"(%arg0) : (i64) -> ()
23 func.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) -> ()
32 func.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) -> ()
41 // CHECK-LABEL: @test_transitive_use_materialization
42 func.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) -> ()
52 func.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) -> ()
61 // CHECK-LABEL: func @test_valid_result_legalization
62 func.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)
67 %result = "test.type_producer"() : () -> f32
68 "foo.return"(%result) : (f32) -> ()
73 // Should not segfault here but gracefully fail.
74 // CHECK-LABEL: func @test_signature_conversion_undo
75 func.func @test_signature_conversion_undo() {
76 // CHECK: test.signature_conversion_undo
77 "test.signature_conversion_undo"() ({
78 // CHECK: ^{{.*}}(%{{.*}}: f32):
80 "test.type_consumer"(%arg0) : (f32) -> ()
81 "test.return"(%arg0) : (f32) -> ()
88 // Should not segfault here but gracefully fail.
89 // CHECK-LABEL: func @test_block_argument_not_converted
90 func.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):
95 "test.return"(%0) : (index) -> ()
102 // Make sure argument type changes aren't implicitly forwarded.
103 func.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}}
107 "test.type_consumer"(%arg0) : (f32) -> ()
108 // expected-note@below{{see existing live user here}}
109 "test.return"(%arg0) : (f32) -> ()
116 // CHECK-LABEL: @recursive_type_conversion
117 func.func @recursive_type_conversion() {
118 // CHECK: !test.test_rec<outer_converted_type, smpla>
119 "test.type_producer"() : () -> !test.test_rec<something, test_rec<something>>
125 // CHECK-LABEL: @unsupported_func_op_interface
126 llvm.func @unsupported_func_op_interface() {
127 // CHECK: llvm.return
133 // CHECK-LABEL: func @test_signature_conversion_no_converter()
134 func.func @test_signature_conversion_no_converter() {
135 // CHECK: "test.signature_conversion_no_converter"() ({
136 // CHECK: ^{{.*}}(%[[arg0:.*]]: f64):
137 "test.signature_conversion_no_converter"() ({
139 // CHECK: "test.legal_op_d"(%[[arg0]]) : (f64) -> ()
140 "test.replace_with_legal_op"(%arg0) : (f32) -> ()
141 "test.return"() : () -> ()