1 // RUN: mlir-opt %s -split-input-file -reconcile-unrealized-casts | FileCheck %s
3 // CHECK-LABEL: @unusedCast
4 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
5 // CHECK: return %[[arg0]] : i64
7 func.func @unusedCast(%arg0: i64) -> i64 {
8 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
14 // CHECK-LABEL: @sameTypes
15 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
16 // CHECK: return %[[arg0]] : i64
18 func.func @sameTypes(%arg0: i64) -> i64 {
19 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i64
26 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
27 // CHECK: return %[[arg0]] : i64
29 func.func @pair(%arg0: i64) -> i64 {
30 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
31 %1 = builtin.unrealized_conversion_cast %0 : i32 to i64
37 // CHECK-LABEL: @symmetricChain
38 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
39 // CHECK: return %[[arg0]] : i64
41 func.func @symmetricChain(%arg0: i64) -> i64 {
42 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
43 %1 = builtin.unrealized_conversion_cast %0 : i32 to i1
44 %2 = builtin.unrealized_conversion_cast %1 : i1 to i32
45 %3 = builtin.unrealized_conversion_cast %2 : i32 to i64
51 // CHECK-LABEL: @asymmetricChain
52 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
53 // CHECK: return %[[arg0]] : i64
55 func.func @asymmetricChain(%arg0: i64) -> i64 {
56 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
57 %1 = builtin.unrealized_conversion_cast %0 : i32 to i1
58 %2 = builtin.unrealized_conversion_cast %1 : i1 to i64
64 // CHECK-LABEL: @unusedChain
65 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
66 // CHECK: return %[[arg0]] : i64
68 func.func @unusedChain(%arg0: i64) -> i64 {
69 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
70 %1 = builtin.unrealized_conversion_cast %0 : i32 to i1
76 // CHECK-LABEL: @bifurcation
77 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
78 // CHECK: %[[result:.*]] = arith.addi %[[arg0]], %[[arg0]] : i64
79 // CHECK: return %[[result]] : i64
81 func.func @bifurcation(%arg0: i64) -> i64 {
82 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
83 %1 = builtin.unrealized_conversion_cast %0 : i32 to i1
84 %2 = builtin.unrealized_conversion_cast %1 : i1 to i64
85 %3 = builtin.unrealized_conversion_cast %1 : i1 to i32
86 %4 = builtin.unrealized_conversion_cast %3 : i32 to i64
87 %5 = arith.addi %2, %4 : i64
93 // CHECK-LABEL: @unusedBifurcation
94 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
95 // CHECK: %[[result:.*]] = arith.addi %[[arg0]], %[[arg0]] : i64
96 // CHECK: return %[[result]] : i64
98 func.func @unusedBifurcation(%arg0: i64) -> i64 {
99 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
100 %1 = builtin.unrealized_conversion_cast %0 : i32 to i1
101 %2 = builtin.unrealized_conversion_cast %1 : i1 to i64
102 %3 = builtin.unrealized_conversion_cast %0 : i32 to i64
103 %4 = arith.addi %arg0, %3 : i64
109 // CHECK-LABEL: @liveSingleCast
110 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i32
111 // CHECK: %[[liveCast:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to i32
112 // CHECK: return %[[liveCast]] : i32
114 func.func @liveSingleCast(%arg0: i64) -> i32 {
115 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
121 // CHECK-LABEL: @liveChain
122 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i32
123 // CHECK: %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to i1
124 // CHECK: %[[cast1:.*]] = builtin.unrealized_conversion_cast %[[cast0]] : i1 to i32
125 // CHECK: return %[[cast1]] : i32
127 func.func @liveChain(%arg0: i64) -> i32 {
128 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i1
129 %1 = builtin.unrealized_conversion_cast %0 : i1 to i32
135 // CHECK-LABEL: @liveBifurcation
136 // CHECK-SAME: (%[[arg0:.*]]: i64) -> i64
137 // CHECK: %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to i32
138 // CHECK: %[[cast2:.*]] = builtin.unrealized_conversion_cast %[[cast0]] : i32 to i1
139 // CHECK: %[[extsi:.*]] = arith.extsi %[[cast2]] : i1 to i64
140 // CHECK: %[[result:.*]] = arith.addi %[[arg0]], %[[extsi]] : i64
141 // CHECK: return %[[result]] : i64
143 func.func @liveBifurcation(%arg0: i64) -> i64 {
144 %0 = builtin.unrealized_conversion_cast %arg0 : i64 to i32
145 %1 = builtin.unrealized_conversion_cast %0 : i32 to i64
146 %2 = builtin.unrealized_conversion_cast %0 : i32 to i1
147 %3 = arith.extsi %2 : i1 to i64
148 %4 = arith.addi %1, %3 : i64
154 // CHECK-LABEL: func @deadNToOneCast(
155 // CHECK-NEXT: return
156 func.func @deadNToOneCast(%arg0: index, %arg1: index) {
157 %0 = builtin.unrealized_conversion_cast %arg0, %arg1 : index, index to i64
163 // CHECK-LABEL: func @swappingOperands(
164 // CHECK-SAME: %[[arg0:.*]]: index, %[[arg1:.*]]: index
165 // CHECK: %[[cast1:.*]]:2 = builtin.unrealized_conversion_cast %[[arg0]], %[[arg1]]
166 // CHECK: %[[cast2:.*]]:2 = builtin.unrealized_conversion_cast %[[cast1]]#1, %[[cast1]]#0
167 // CHECK: %[[cast3:.*]]:2 = builtin.unrealized_conversion_cast %[[cast2]]#0, %[[cast2]]#1
168 // CHECK: return %[[cast3]]#0, %[[cast3]]#1
169 func.func @swappingOperands(%arg0: index, %arg1: index) -> (index, index) {
170 %0:2 = builtin.unrealized_conversion_cast %arg0, %arg1 : index, index to i64, i64
171 %1:2 = builtin.unrealized_conversion_cast %0#1, %0#0 : i64, i64 to i32, i32
172 %2:2 = builtin.unrealized_conversion_cast %1#0, %1#1 : i32, i32 to index, index
173 return %2#0, %2#1 : index, index
178 // CHECK-LABEL: func @matchingOperands(
179 // CHECK-SAME: %[[arg0:.*]]: index, %[[arg1:.*]]: index
180 // CHECK: return %[[arg0]], %[[arg1]]
181 func.func @matchingOperands(%arg0: index, %arg1: index) -> (index, index) {
182 %0:2 = builtin.unrealized_conversion_cast %arg0, %arg1 : index, index to i64, i64
183 %1:3 = builtin.unrealized_conversion_cast %0#0, %0#1 : i64, i64 to i32, i32, i32
184 %2:2 = builtin.unrealized_conversion_cast %1#0, %1#1, %1#2 : i32, i32, i32 to index, index
185 return %2#0, %2#1 : index, index
190 // CHECK-LABEL: func @emptyCast()
191 // CHECK: %[[cast:.*]] = builtin.unrealized_conversion_cast to index
192 // CHECK: return %[[cast]]
193 func.func @emptyCast() -> index {
194 %0 = builtin.unrealized_conversion_cast to index