aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/Transforms/test-legalize-type-conversion.mlir
blob: b35cda8e724f6b10240f0287e402b27f1c5c08e0 (plain)
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
// RUN: mlir-opt %s -test-legalize-type-conversion -allow-unregistered-dialect -split-input-file -verify-diagnostics | FileCheck %s


func.func @test_invalid_arg_materialization(
  // expected-error@below {{failed to materialize conversion for block argument #0 that remained live after conversion, type was 'i16'}}
  %arg0: i16) {
  // expected-note@below {{see existing live user here}}
  "foo.return"(%arg0) : (i16) -> ()
}

// -----

// CHECK-LABEL: func @test_valid_arg_materialization
func.func @test_valid_arg_materialization(%arg0: i64) {
  // CHECK: %[[ARG:.*]] = "test.type_producer"
  // CHECK: "foo.return"(%[[ARG]]) : (i64)

  "foo.return"(%arg0) : (i64) -> ()
}

// -----

func.func @test_invalid_result_materialization() {
  // expected-error@below {{failed to materialize conversion for result #0 of operation 'test.type_producer' that remained live after conversion}}
  %result = "test.type_producer"() : () -> f16

  // expected-note@below {{see existing live user here}}
  "foo.return"(%result) : (f16) -> ()
}

// -----

func.func @test_invalid_result_materialization() {
  // expected-error@below {{failed to materialize conversion for result #0 of operation 'test.type_producer' that remained live after conversion}}
  %result = "test.type_producer"() : () -> f16

  // expected-note@below {{see existing live user here}}
  "foo.return"(%result) : (f16) -> ()
}

// -----

// CHECK-LABEL: @test_transitive_use_materialization
func.func @test_transitive_use_materialization() {
  // CHECK: %[[V:.*]] = "test.type_producer"() : () -> f64
  // CHECK: %[[C:.*]] = "test.cast"(%[[V]]) : (f64) -> f32
  %result = "test.another_type_producer"() : () -> f32
  // CHECK: "foo.return"(%[[C]])
  "foo.return"(%result) : (f32) -> ()
}

// -----

func.func @test_transitive_use_invalid_materialization() {
  // expected-error@below {{failed to materialize conversion for result #0 of operation 'test.type_producer' that remained live after conversion}}
  %result = "test.another_type_producer"() : () -> f16
  // expected-note@below {{see existing live user here}}
  "foo.return"(%result) : (f16) -> ()
}

// -----

// CHECK-LABEL: func @test_valid_result_legalization
func.func @test_valid_result_legalization() {
  // CHECK: %[[RESULT:.*]] = "test.type_producer"() : () -> f64
  // CHECK: %[[CAST:.*]] = "test.cast"(%[[RESULT]]) : (f64) -> f32
  // CHECK: "foo.return"(%[[CAST]]) : (f32)

  %result = "test.type_producer"() : () -> f32
  "foo.return"(%result) : (f32) -> ()
}

// -----

// Should not segfault here but gracefully fail.
// CHECK-LABEL: func @test_signature_conversion_undo
func.func @test_signature_conversion_undo() {
  // CHECK: test.signature_conversion_undo
  "test.signature_conversion_undo"() ({
  // CHECK: ^{{.*}}(%{{.*}}: f32):
  ^bb0(%arg0: f32):
    "test.type_consumer"(%arg0) : (f32) -> ()
    "test.return"(%arg0) : (f32) -> ()
  }) : () -> ()
  return
}

// -----

// Should not segfault here but gracefully fail.
// CHECK-LABEL: func @test_block_argument_not_converted
func.func @test_block_argument_not_converted() {
  "test.unsupported_block_arg_type"() ({
    // NOTE: The test pass does not convert `index` types.
    // CHECK: ^bb0({{.*}}: index):
    ^bb0(%0 : index):
      "test.return"(%0) : (index) -> ()
  }) : () -> ()
  return
}

// -----

// Make sure argument type changes aren't implicitly forwarded.
func.func @test_signature_conversion_no_converter() {
  "test.signature_conversion_no_converter"() ({
  // expected-error@below {{failed to materialize conversion for block argument #0 that remained live after conversion}}
  ^bb0(%arg0: f32):
    // expected-note@below {{see existing live user here}}
    "test.type_consumer"(%arg0) : (f32) -> ()
    "test.return"(%arg0) : (f32) -> ()
  }) : () -> ()
  return
}

// -----

// CHECK-LABEL: @recursive_type_conversion
func.func @recursive_type_conversion() {
  // CHECK:  !test.test_rec<outer_converted_type, smpla>
  "test.type_producer"() : () -> !test.test_rec<something, test_rec<something>>
  return
}

// -----

// CHECK-LABEL: @unsupported_func_op_interface
llvm.func @unsupported_func_op_interface() {
  // CHECK: llvm.return
  llvm.return
}