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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
// RUN: mlir-opt %s -canonicalize="test-convergence" | FileCheck %s
// CHECK-LABEL: func @create_of_real_and_imag
// CHECK-SAME: (%[[CPLX:.*]]: complex<f32>)
func.func @create_of_real_and_imag(%cplx: complex<f32>) -> complex<f32> {
// CHECK-NEXT: return %[[CPLX]] : complex<f32>
%real = complex.re %cplx : complex<f32>
%imag = complex.im %cplx : complex<f32>
%complex = complex.create %real, %imag : complex<f32>
return %complex : complex<f32>
}
// CHECK-LABEL: func @create_of_real_and_imag_different_operand
// CHECK-SAME: (%[[CPLX:.*]]: complex<f32>, %[[CPLX2:.*]]: complex<f32>)
func.func @create_of_real_and_imag_different_operand(
%cplx: complex<f32>, %cplx2 : complex<f32>) -> complex<f32> {
// CHECK-NEXT: %[[REAL:.*]] = complex.re %[[CPLX]] : complex<f32>
// CHECK-NEXT: %[[IMAG:.*]] = complex.im %[[CPLX2]] : complex<f32>
// CHECK-NEXT: %[[COMPLEX:.*]] = complex.create %[[REAL]], %[[IMAG]] : complex<f32>
%real = complex.re %cplx : complex<f32>
%imag = complex.im %cplx2 : complex<f32>
%complex = complex.create %real, %imag : complex<f32>
return %complex: complex<f32>
}
// CHECK-LABEL: func @real_of_const(
func.func @real_of_const() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 1.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%complex = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%1 = complex.re %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @real_of_create_op(
func.func @real_of_create_op() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 1.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%real = arith.constant 1.0 : f32
%imag = arith.constant 0.0 : f32
%complex = complex.create %real, %imag : complex<f32>
%1 = complex.re %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @imag_of_const(
func.func @imag_of_const() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%complex = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%1 = complex.im %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @imag_of_create_op(
func.func @imag_of_create_op() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%real = arith.constant 1.0 : f32
%imag = arith.constant 0.0 : f32
%complex = complex.create %real, %imag : complex<f32>
%1 = complex.im %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @complex_add_sub_lhs
func.func @complex_add_sub_lhs() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%complex2 = complex.constant [0.0 : f32, 2.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%sub = complex.sub %complex1, %complex2 : complex<f32>
%add = complex.add %sub, %complex2 : complex<f32>
return %add : complex<f32>
}
// CHECK-LABEL: func @complex_add_sub_rhs
func.func @complex_add_sub_rhs() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%complex2 = complex.constant [0.0 : f32, 2.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%sub = complex.sub %complex1, %complex2 : complex<f32>
%add = complex.add %complex2, %sub : complex<f32>
return %add : complex<f32>
}
// CHECK-LABEL: func @complex_neg_neg
func.func @complex_neg_neg() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%neg1 = complex.neg %complex1 : complex<f32>
%neg2 = complex.neg %neg1 : complex<f32>
return %neg2 : complex<f32>
}
// CHECK-LABEL: func @complex_log_exp
func.func @complex_log_exp() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%exp = complex.exp %complex1 : complex<f32>
%log = complex.log %exp : complex<f32>
return %log : complex<f32>
}
// CHECK-LABEL: func @complex_exp_log
func.func @complex_exp_log() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%log = complex.log %complex1 : complex<f32>
%exp = complex.exp %log : complex<f32>
return %exp : complex<f32>
}
// CHECK-LABEL: func @complex_conj_conj
func.func @complex_conj_conj() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%conj1 = complex.conj %complex1 : complex<f32>
%conj2 = complex.conj %conj1 : complex<f32>
return %conj2 : complex<f32>
}
// CHECK-LABEL: func @complex_add_zero
func.func @complex_add_zero() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%complex2 = complex.constant [0.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%add = complex.add %complex1, %complex2 : complex<f32>
return %add : complex<f32>
}
// CHECK-LABEL: func @complex_sub_add_lhs
func.func @complex_sub_add_lhs() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%complex2 = complex.constant [0.0 : f32, 2.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%add = complex.add %complex1, %complex2 : complex<f32>
%sub = complex.sub %add, %complex2 : complex<f32>
return %sub : complex<f32>
}
// CHECK-LABEL: func @complex_sub_zero
func.func @complex_sub_zero() -> complex<f32> {
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%complex2 = complex.constant [0.0 : f32, 0.0 : f32] : complex<f32>
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
%sub = complex.sub %complex1, %complex2 : complex<f32>
return %sub : complex<f32>
}
// CHECK-LABEL: func @re_neg
// CHECK-SAME: (%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)
func.func @re_neg(%arg0: f32, %arg1: f32) -> f32 {
%create = complex.create %arg0, %arg1: complex<f32>
// CHECK: %[[NEG:.*]] = arith.negf %[[ARG0]]
%neg = complex.neg %create : complex<f32>
%re = complex.re %neg : complex<f32>
// CHECK-NEXT: return %[[NEG]]
return %re : f32
}
// CHECK-LABEL: func @im_neg
// CHECK-SAME: (%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)
func.func @im_neg(%arg0: f32, %arg1: f32) -> f32 {
%create = complex.create %arg0, %arg1: complex<f32>
// CHECK: %[[NEG:.*]] = arith.negf %[[ARG1]]
%neg = complex.neg %create : complex<f32>
%im = complex.im %neg : complex<f32>
// CHECK-NEXT: return %[[NEG]]
return %im : f32
}
// CHECK-LABEL: func @mul_one_f16
// CHECK-SAME: (%[[ARG0:.*]]: f16, %[[ARG1:.*]]: f16) -> complex<f16>
func.func @mul_one_f16(%arg0: f16, %arg1: f16) -> complex<f16> {
%create = complex.create %arg0, %arg1: complex<f16>
%one = complex.constant [1.0 : f16, 0.0 : f16] : complex<f16>
%mul = complex.mul %create, %one : complex<f16>
// CHECK: %[[CREATE:.*]] = complex.create %[[ARG0]], %[[ARG1]] : complex<f16>
// CHECK-NEXT: return %[[CREATE]]
return %mul : complex<f16>
}
// CHECK-LABEL: func @mul_one_f32
// CHECK-SAME: (%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32) -> complex<f32>
func.func @mul_one_f32(%arg0: f32, %arg1: f32) -> complex<f32> {
%create = complex.create %arg0, %arg1: complex<f32>
%one = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%mul = complex.mul %create, %one : complex<f32>
// CHECK: %[[CREATE:.*]] = complex.create %[[ARG0]], %[[ARG1]] : complex<f32>
// CHECK-NEXT: return %[[CREATE]]
return %mul : complex<f32>
}
// CHECK-LABEL: func @mul_one_f64
// CHECK-SAME: (%[[ARG0:.*]]: f64, %[[ARG1:.*]]: f64) -> complex<f64>
func.func @mul_one_f64(%arg0: f64, %arg1: f64) -> complex<f64> {
%create = complex.create %arg0, %arg1: complex<f64>
%one = complex.constant [1.0 : f64, 0.0 : f64] : complex<f64>
%mul = complex.mul %create, %one : complex<f64>
// CHECK: %[[CREATE:.*]] = complex.create %[[ARG0]], %[[ARG1]] : complex<f64>
// CHECK-NEXT: return %[[CREATE]]
return %mul : complex<f64>
}
// CHECK-LABEL: func @mul_one_f80
// CHECK-SAME: (%[[ARG0:.*]]: f80, %[[ARG1:.*]]: f80) -> complex<f80>
func.func @mul_one_f80(%arg0: f80, %arg1: f80) -> complex<f80> {
%create = complex.create %arg0, %arg1: complex<f80>
%one = complex.constant [1.0 : f80, 0.0 : f80] : complex<f80>
%mul = complex.mul %create, %one : complex<f80>
// CHECK: %[[CREATE:.*]] = complex.create %[[ARG0]], %[[ARG1]] : complex<f80>
// CHECK-NEXT: return %[[CREATE]]
return %mul : complex<f80>
}
// CHECK-LABEL: func @mul_one_f128
// CHECK-SAME: (%[[ARG0:.*]]: f128, %[[ARG1:.*]]: f128) -> complex<f128>
func.func @mul_one_f128(%arg0: f128, %arg1: f128) -> complex<f128> {
%create = complex.create %arg0, %arg1: complex<f128>
%one = complex.constant [1.0 : f128, 0.0 : f128] : complex<f128>
%mul = complex.mul %create, %one : complex<f128>
// CHECK: %[[CREATE:.*]] = complex.create %[[ARG0]], %[[ARG1]] : complex<f128>
// CHECK-NEXT: return %[[CREATE]]
return %mul : complex<f128>
}
// CHECK-LABEL: func @fold_between_complex
// CHECK-SAME: %[[ARG0:.*]]: complex<f32>
func.func @fold_between_complex(%arg0 : complex<f32>) -> complex<f32> {
%0 = complex.bitcast %arg0 : complex<f32> to i64
%1 = complex.bitcast %0 : i64 to complex<f32>
// CHECK: return %[[ARG0]] : complex<f32>
func.return %1 : complex<f32>
}
// CHECK-LABEL: func @fold_between_i64
// CHECK-SAME: %[[ARG0:.*]]: i64
func.func @fold_between_i64(%arg0 : i64) -> i64 {
%0 = complex.bitcast %arg0 : i64 to complex<f32>
%1 = complex.bitcast %0 : complex<f32> to i64
// CHECK: return %[[ARG0]] : i64
func.return %1 : i64
}
// CHECK-LABEL: func @canon_arith_bitcast
// CHECK-SAME: %[[ARG0:.*]]: f64
func.func @canon_arith_bitcast(%arg0 : f64) -> i64 {
%0 = complex.bitcast %arg0 : f64 to complex<f32>
%1 = complex.bitcast %0 : complex<f32> to i64
// CHECK: %[[R0:.+]] = arith.bitcast %[[ARG0]]
// CHECK: return %[[R0]] : i64
func.return %1 : i64
}
// CHECK-LABEL: func @double_bitcast
// CHECK-SAME: %[[ARG0:.*]]: f64
func.func @double_bitcast(%arg0 : f64) -> complex<f32> {
// CHECK: %[[R0:.+]] = complex.bitcast %[[ARG0]]
%0 = arith.bitcast %arg0 : f64 to i64
%1 = complex.bitcast %0 : i64 to complex<f32>
// CHECK: return %[[R0]] : complex<f32>
func.return %1 : complex<f32>
}
// CHECK-LABEL: func @double_reverse_bitcast
// CHECK-SAME: %[[ARG0:.*]]: complex<f32>
func.func @double_reverse_bitcast(%arg0 : complex<f32>) -> f64 {
// CHECK: %[[R0:.+]] = complex.bitcast %[[ARG0]]
%0 = complex.bitcast %arg0 : complex<f32> to i64
%1 = arith.bitcast %0 : i64 to f64
// CHECK: return %[[R0]] : f64
func.return %1 : f64
}
|