673 lines · plain
1// RUN: mlir-opt %s -allow-unregistered-dialect -split-input-file -pass-pipeline='builtin.module(convert-math-to-rocdl{chipset=gfx803})' | FileCheck %s --check-prefix=PRE92// RUN: mlir-opt %s -allow-unregistered-dialect -split-input-file -pass-pipeline='builtin.module(convert-math-to-rocdl{chipset=gfx942})' | FileCheck %s --check-prefix=POST93 4module @test_module {5 // CHECK: llvm.func @__ocml_fmod_f16(f16, f16) -> f166 // CHECK: llvm.func @__ocml_fmod_f32(f32, f32) -> f327 // CHECK: llvm.func @__ocml_fmod_f64(f64, f64) -> f648 // CHECK-LABEL: func @arith_remf9 func.func @arith_remf(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {10 %result16 = arith.remf %arg_f16, %arg_f16 : f1611 // CHECK: llvm.call @__ocml_fmod_f16(%{{.*}}, %{{.*}}) : (f16, f16) -> f1612 %result32 = arith.remf %arg_f32, %arg_f32 : f3213 // CHECK: llvm.call @__ocml_fmod_f32(%{{.*}}, %{{.*}}) : (f32, f32) -> f3214 %result64 = arith.remf %arg_f64, %arg_f64 : f6415 // CHECK: llvm.call @__ocml_fmod_f64(%{{.*}}, %{{.*}}) : (f64, f64) -> f6416 func.return %result16, %result32, %result64 : f16, f32, f6417 }18}19 20// -----21 22module @test_module {23 // CHECK: llvm.func @__ocml_acos_f16(f16) -> f1624 // CHECK: llvm.func @__ocml_acos_f32(f32) -> f3225 // CHECK: llvm.func @__ocml_acos_f64(f64) -> f6426 // CHECK-LABEL: func @math_acos27 func.func @math_acos(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {28 %result16 = math.acos %arg_f16 : f1629 // CHECK: llvm.call @__ocml_acos_f16(%{{.*}}) : (f16) -> f1630 %result32 = math.acos %arg_f32 : f3231 // CHECK: llvm.call @__ocml_acos_f32(%{{.*}}) : (f32) -> f3232 %result64 = math.acos %arg_f64 : f6433 // CHECK: llvm.call @__ocml_acos_f64(%{{.*}}) : (f64) -> f6434 func.return %result16, %result32, %result64 : f16, f32, f6435 }36}37 38// -----39 40module @test_module {41 // CHECK: llvm.func @__ocml_acosh_f16(f16) -> f1642 // CHECK: llvm.func @__ocml_acosh_f32(f32) -> f3243 // CHECK: llvm.func @__ocml_acosh_f64(f64) -> f6444 // CHECK-LABEL: func @math_acosh45 func.func @math_acosh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {46 %result16 = math.acosh %arg_f16 : f1647 // CHECK: llvm.call @__ocml_acosh_f16(%{{.*}}) : (f16) -> f1648 %result32 = math.acosh %arg_f32 : f3249 // CHECK: llvm.call @__ocml_acosh_f32(%{{.*}}) : (f32) -> f3250 %result64 = math.acosh %arg_f64 : f6451 // CHECK: llvm.call @__ocml_acosh_f64(%{{.*}}) : (f64) -> f6452 func.return %result16, %result32, %result64 : f16, f32, f6453 }54}55 56// -----57 58module @test_module {59 // CHECK: llvm.func @__ocml_asin_f16(f16) -> f1660 // CHECK: llvm.func @__ocml_asin_f32(f32) -> f3261 // CHECK: llvm.func @__ocml_asin_f64(f64) -> f6462 // CHECK-LABEL: func @math_asin63 func.func @math_asin(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {64 %result16 = math.asin %arg_f16 : f1665 // CHECK: llvm.call @__ocml_asin_f16(%{{.*}}) : (f16) -> f1666 %result32 = math.asin %arg_f32 : f3267 // CHECK: llvm.call @__ocml_asin_f32(%{{.*}}) : (f32) -> f3268 %result64 = math.asin %arg_f64 : f6469 // CHECK: llvm.call @__ocml_asin_f64(%{{.*}}) : (f64) -> f6470 func.return %result16, %result32, %result64 : f16, f32, f6471 }72}73 74// -----75 76module @test_module {77 // CHECK: llvm.func @__ocml_asinh_f16(f16) -> f1678 // CHECK: llvm.func @__ocml_asinh_f32(f32) -> f3279 // CHECK: llvm.func @__ocml_asinh_f64(f64) -> f6480 // CHECK-LABEL: func @math_asinh81 func.func @math_asinh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {82 %result16 = math.asinh %arg_f16 : f1683 // CHECK: llvm.call @__ocml_asinh_f16(%{{.*}}) : (f16) -> f1684 %result32 = math.asinh %arg_f32 : f3285 // CHECK: llvm.call @__ocml_asinh_f32(%{{.*}}) : (f32) -> f3286 %result64 = math.asinh %arg_f64 : f6487 // CHECK: llvm.call @__ocml_asinh_f64(%{{.*}}) : (f64) -> f6488 func.return %result16, %result32, %result64 : f16, f32, f6489 }90}91 92// -----93 94module @test_module {95 // CHECK: llvm.func @__ocml_atan_f16(f16) -> f1696 // CHECK: llvm.func @__ocml_atan_f32(f32) -> f3297 // CHECK: llvm.func @__ocml_atan_f64(f64) -> f6498 // CHECK-LABEL: func @math_atan99 func.func @math_atan(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {100 %result16 = math.atan %arg_f16 : f16101 // CHECK: llvm.call @__ocml_atan_f16(%{{.*}}) : (f16) -> f16102 %result32 = math.atan %arg_f32 : f32103 // CHECK: llvm.call @__ocml_atan_f32(%{{.*}}) : (f32) -> f32104 %result64 = math.atan %arg_f64 : f64105 // CHECK: llvm.call @__ocml_atan_f64(%{{.*}}) : (f64) -> f64106 func.return %result16, %result32, %result64 : f16, f32, f64107 }108}109 110// -----111 112module @test_module {113 // CHECK: llvm.func @__ocml_atanh_f16(f16) -> f16114 // CHECK: llvm.func @__ocml_atanh_f32(f32) -> f32115 // CHECK: llvm.func @__ocml_atanh_f64(f64) -> f64116 // CHECK-LABEL: func @math_atanh117 func.func @math_atanh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {118 %result16 = math.atanh %arg_f16 : f16119 // CHECK: llvm.call @__ocml_atanh_f16(%{{.*}}) : (f16) -> f16120 %result32 = math.atanh %arg_f32 : f32121 // CHECK: llvm.call @__ocml_atanh_f32(%{{.*}}) : (f32) -> f32122 %result64 = math.atanh %arg_f64 : f64123 // CHECK: llvm.call @__ocml_atanh_f64(%{{.*}}) : (f64) -> f64124 func.return %result16, %result32, %result64 : f16, f32, f64125 }126}127 128// -----129 130module @test_module {131 // CHECK: llvm.func @__ocml_atan2_f16(f16, f16) -> f16132 // CHECK: llvm.func @__ocml_atan2_f32(f32, f32) -> f32133 // CHECK: llvm.func @__ocml_atan2_f64(f64, f64) -> f64134 // CHECK-LABEL: func @math_atan2135 func.func @math_atan2(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {136 %result16 = math.atan2 %arg_f16, %arg_f16 : f16137 // CHECK: llvm.call @__ocml_atan2_f16(%{{.*}}, %{{.*}}) : (f16, f16) -> f16138 %result32 = math.atan2 %arg_f32, %arg_f32 : f32139 // CHECK: llvm.call @__ocml_atan2_f32(%{{.*}}, %{{.*}}) : (f32, f32) -> f32140 %result64 = math.atan2 %arg_f64, %arg_f64 : f64141 // CHECK: llvm.call @__ocml_atan2_f64(%{{.*}}, %{{.*}}) : (f64, f64) -> f64142 func.return %result16, %result32, %result64 : f16, f32, f64143 }144}145 146// -----147 148module @test_module {149 // CHECK: llvm.func @__ocml_cbrt_f16(f16) -> f16150 // CHECK: llvm.func @__ocml_cbrt_f32(f32) -> f32151 // CHECK: llvm.func @__ocml_cbrt_f64(f64) -> f64152 // CHECK-LABEL: func @math_cbrt153 func.func @math_cbrt(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {154 %result16 = math.cbrt %arg_f16 : f16155 // CHECK: llvm.call @__ocml_cbrt_f16(%{{.*}}) : (f16) -> f16156 %result32 = math.cbrt %arg_f32 : f32157 // CHECK: llvm.call @__ocml_cbrt_f32(%{{.*}}) : (f32) -> f32158 %result64 = math.cbrt %arg_f64 : f64159 // CHECK: llvm.call @__ocml_cbrt_f64(%{{.*}}) : (f64) -> f64160 func.return %result16, %result32, %result64 : f16, f32, f64161 }162}163 164// -----165 166module @test_module {167 // CHECK: llvm.func @__ocml_ceil_f16(f16) -> f16168 // CHECK: llvm.func @__ocml_ceil_f32(f32) -> f32169 // CHECK: llvm.func @__ocml_ceil_f64(f64) -> f64170 // CHECK-LABEL: func @math_ceil171 func.func @math_ceil(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {172 %result16 = math.ceil %arg_f16 : f16173 // CHECK: llvm.call @__ocml_ceil_f16(%{{.*}}) : (f16) -> f16174 %result32 = math.ceil %arg_f32 : f32175 // CHECK: llvm.call @__ocml_ceil_f32(%{{.*}}) : (f32) -> f32176 %result64 = math.ceil %arg_f64 : f64177 // CHECK: llvm.call @__ocml_ceil_f64(%{{.*}}) : (f64) -> f64178 func.return %result16, %result32, %result64 : f16, f32, f64179 }180}181 182// -----183 184module @test_module {185 // CHECK: llvm.func @__ocml_cos_f16(f16) -> f16186 // CHECK: llvm.func @__ocml_cos_f32(f32) -> f32187 // CHECK: llvm.func @__ocml_cos_f64(f64) -> f64188 // CHECK-LABEL: func @math_cos189 func.func @math_cos(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {190 %result16 = math.cos %arg_f16 : f16191 // CHECK: llvm.call @__ocml_cos_f16(%{{.*}}) : (f16) -> f16192 %result32 = math.cos %arg_f32 : f32193 // CHECK: llvm.call @__ocml_cos_f32(%{{.*}}) : (f32) -> f32194 %result64 = math.cos %arg_f64 : f64195 // CHECK: llvm.call @__ocml_cos_f64(%{{.*}}) : (f64) -> f64196 func.return %result16, %result32, %result64 : f16, f32, f64197 }198}199 200// -----201 202module @test_module {203 // CHECK: llvm.func @__ocml_cosh_f16(f16) -> f16204 // CHECK: llvm.func @__ocml_cosh_f32(f32) -> f32205 // CHECK: llvm.func @__ocml_cosh_f64(f64) -> f64206 // CHECK-LABEL: func @math_cosh207 func.func @math_cosh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {208 %result16 = math.cosh %arg_f16 : f16209 // CHECK: llvm.call @__ocml_cosh_f16(%{{.*}}) : (f16) -> f16210 %result32 = math.cosh %arg_f32 : f32211 // CHECK: llvm.call @__ocml_cosh_f32(%{{.*}}) : (f32) -> f32212 %result64 = math.cosh %arg_f64 : f64213 // CHECK: llvm.call @__ocml_cosh_f64(%{{.*}}) : (f64) -> f64214 func.return %result16, %result32, %result64 : f16, f32, f64215 }216}217 218// -----219 220module @test_module {221 // CHECK: llvm.func @__ocml_sinh_f16(f16) -> f16222 // CHECK: llvm.func @__ocml_sinh_f32(f32) -> f32223 // CHECK: llvm.func @__ocml_sinh_f64(f64) -> f64224 // CHECK-LABEL: func @math_sinh225 func.func @math_sinh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {226 %result16 = math.sinh %arg_f16 : f16227 // CHECK: llvm.call @__ocml_sinh_f16(%{{.*}}) : (f16) -> f16228 %result32 = math.sinh %arg_f32 : f32229 // CHECK: llvm.call @__ocml_sinh_f32(%{{.*}}) : (f32) -> f32230 %result64 = math.sinh %arg_f64 : f64231 // CHECK: llvm.call @__ocml_sinh_f64(%{{.*}}) : (f64) -> f64232 func.return %result16, %result32, %result64 : f16, f32, f64233 }234}235 236// -----237 238module @test_module {239 // CHECK: llvm.func @__ocml_exp_f16(f16) -> f16240 // CHECK: llvm.func @__ocml_exp_f64(f64) -> f64241 // CHECK-LABEL: func @math_exp242 func.func @math_exp(%arg_f16 : f16, %arg_f64 : f64) -> (f16, f64) {243 %result16 = math.exp %arg_f16 : f16244 // CHECK: llvm.call @__ocml_exp_f16(%{{.*}}) : (f16) -> f16245 %result64 = math.exp %arg_f64 : f64246 // CHECK: llvm.call @__ocml_exp_f64(%{{.*}}) : (f64) -> f64247 func.return %result16, %result64 : f16, f64248 }249}250 251// -----252 253module @test_module {254 // CHECK: llvm.func @__ocml_exp2_f16(f16) -> f16255 // CHECK: llvm.func @__ocml_exp2_f32(f32) -> f32256 // CHECK: llvm.func @__ocml_exp2_f64(f64) -> f64257 // CHECK-LABEL: func @math_exp2258 func.func @math_exp2(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {259 %result16 = math.exp2 %arg_f16 : f16260 // CHECK: llvm.call @__ocml_exp2_f16(%{{.*}}) : (f16) -> f16261 %result32 = math.exp2 %arg_f32 : f32262 // CHECK: llvm.call @__ocml_exp2_f32(%{{.*}}) : (f32) -> f32263 %result64 = math.exp2 %arg_f64 : f64264 // CHECK: llvm.call @__ocml_exp2_f64(%{{.*}}) : (f64) -> f64265 func.return %result16, %result32, %result64 : f16, f32, f64266 }267}268 269// -----270 271module @test_module {272 // CHECK: llvm.func @__ocml_expm1_f16(f16) -> f16273 // CHECK: llvm.func @__ocml_expm1_f32(f32) -> f32274 // CHECK: llvm.func @__ocml_expm1_f64(f64) -> f64275 // CHECK-LABEL: func @math_expm1276 func.func @math_expm1(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {277 %result16 = math.expm1 %arg_f16 : f16278 // CHECK: llvm.call @__ocml_expm1_f16(%{{.*}}) : (f16) -> f16279 %result32 = math.expm1 %arg_f32 : f32280 // CHECK: llvm.call @__ocml_expm1_f32(%{{.*}}) : (f32) -> f32281 %result64 = math.expm1 %arg_f64 : f64282 // CHECK: llvm.call @__ocml_expm1_f64(%{{.*}}) : (f64) -> f64283 func.return %result16, %result32, %result64 : f16, f32, f64284 }285}286 287// -----288 289module @test_module {290 // CHECK: llvm.func @__ocml_floor_f16(f16) -> f16291 // CHECK: llvm.func @__ocml_floor_f32(f32) -> f32292 // CHECK: llvm.func @__ocml_floor_f64(f64) -> f64293 // CHECK-LABEL: func @math_floor294 func.func @math_floor(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {295 %result16 = math.floor %arg_f16 : f16296 // CHECK: llvm.call @__ocml_floor_f16(%{{.*}}) : (f16) -> f16297 %result32 = math.floor %arg_f32 : f32298 // CHECK: llvm.call @__ocml_floor_f32(%{{.*}}) : (f32) -> f32299 %result64 = math.floor %arg_f64 : f64300 // CHECK: llvm.call @__ocml_floor_f64(%{{.*}}) : (f64) -> f64301 func.return %result16, %result32, %result64 : f16, f32, f64302 }303}304 305// -----306 307module @test_module {308 // CHECK: llvm.func @__ocml_log_f16(f16) -> f16309 // CHECK: llvm.func @__ocml_log_f64(f64) -> f64310 // CHECK-LABEL: func @math_log311 func.func @math_log(%arg_f16 : f16, %arg_f64 : f64) -> (f16, f64) {312 %result16 = math.log %arg_f16 : f16313 // CHECK: llvm.call @__ocml_log_f16(%{{.*}}) : (f16) -> f16314 %result64 = math.log %arg_f64 : f64315 // CHECK: llvm.call @__ocml_log_f64(%{{.*}}) : (f64) -> f64316 func.return %result16, %result64 : f16, f64317 }318}319 320// -----321 322module @test_module {323 // CHECK: llvm.func @__ocml_log10_f16(f16) -> f16324 // CHECK: llvm.func @__ocml_log10_f32(f32) -> f32325 // CHECK: llvm.func @__ocml_log10_f64(f64) -> f64326 // CHECK-LABEL: func @math_log10327 func.func @math_log10(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {328 %result16 = math.log10 %arg_f16 : f16329 // CHECK: llvm.call @__ocml_log10_f16(%{{.*}}) : (f16) -> f16330 %result32 = math.log10 %arg_f32 : f32331 // CHECK: llvm.call @__ocml_log10_f32(%{{.*}}) : (f32) -> f32332 %result64 = math.log10 %arg_f64 : f64333 // CHECK: llvm.call @__ocml_log10_f64(%{{.*}}) : (f64) -> f64334 func.return %result16, %result32, %result64 : f16, f32, f64335 }336}337 338// -----339 340module @test_module {341 // CHECK: llvm.func @__ocml_log1p_f16(f16) -> f16342 // CHECK: llvm.func @__ocml_log1p_f32(f32) -> f32343 // CHECK: llvm.func @__ocml_log1p_f64(f64) -> f64344 // CHECK-LABEL: func @math_log1p345 func.func @math_log1p(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {346 %result16 = math.log1p %arg_f16 : f16347 // CHECK: llvm.call @__ocml_log1p_f16(%{{.*}}) : (f16) -> f16348 %result32 = math.log1p %arg_f32 : f32349 // CHECK: llvm.call @__ocml_log1p_f32(%{{.*}}) : (f32) -> f32350 %result64 = math.log1p %arg_f64 : f64351 // CHECK: llvm.call @__ocml_log1p_f64(%{{.*}}) : (f64) -> f64352 func.return %result16, %result32, %result64 : f16, f32, f64353 }354}355 356// -----357 358module @test_module {359 // CHECK: llvm.func @__ocml_pow_f16(f16, f16) -> f16360 // CHECK: llvm.func @__ocml_pow_f32(f32, f32) -> f32361 // CHECK: llvm.func @__ocml_pow_f64(f64, f64) -> f64362 // CHECK-LABEL: func @math_powf363 func.func @math_powf(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {364 %result16 = math.powf %arg_f16, %arg_f16 : f16365 // CHECK: llvm.call @__ocml_pow_f16(%{{.*}}, %{{.*}}) : (f16, f16) -> f16366 %result32 = math.powf %arg_f32, %arg_f32 : f32367 // CHECK: llvm.call @__ocml_pow_f32(%{{.*}}, %{{.*}}) : (f32, f32) -> f32368 %result64 = math.powf %arg_f64, %arg_f64 : f64369 // CHECK: llvm.call @__ocml_pow_f64(%{{.*}}, %{{.*}}) : (f64, f64) -> f64370 func.return %result16, %result32, %result64 : f16, f32, f64371 }372}373 374// -----375 376module @test_module {377 // CHECK: llvm.func @__ocml_rsqrt_f16(f16) -> f16378 // CHECK: llvm.func @__ocml_rsqrt_f32(f32) -> f32379 // CHECK: llvm.func @__ocml_rsqrt_f64(f64) -> f64380 // CHECK-LABEL: func @math_rsqrt381 func.func @math_rsqrt(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {382 %result16 = math.rsqrt %arg_f16 : f16383 // CHECK: llvm.call @__ocml_rsqrt_f16(%{{.*}}) : (f16) -> f16384 %result32 = math.rsqrt %arg_f32 : f32385 // CHECK: llvm.call @__ocml_rsqrt_f32(%{{.*}}) : (f32) -> f32386 %result64 = math.rsqrt %arg_f64 : f64387 // CHECK: llvm.call @__ocml_rsqrt_f64(%{{.*}}) : (f64) -> f64388 func.return %result16, %result32, %result64 : f16, f32, f64389 }390}391 392// -----393 394module @test_module {395 // CHECK: llvm.func @__ocml_sin_f16(f16) -> f16396 // CHECK: llvm.func @__ocml_sin_f32(f32) -> f32397 // CHECK: llvm.func @__ocml_sin_f64(f64) -> f64398 // CHECK-LABEL: func @math_sin399 func.func @math_sin(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {400 %result16 = math.sin %arg_f16 : f16401 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16402 %result32 = math.sin %arg_f32 : f32403 // CHECK: llvm.call @__ocml_sin_f32(%{{.*}}) : (f32) -> f32404 %result64 = math.sin %arg_f64 : f64405 // CHECK: llvm.call @__ocml_sin_f64(%{{.*}}) : (f64) -> f64406 func.return %result16, %result32, %result64 : f16, f32, f64407 }408}409 410// -----411 412module @test_module {413 // CHECK: llvm.func @__ocml_tanh_f16(f16) -> f16414 // CHECK: llvm.func @__ocml_tanh_f32(f32) -> f32415 // CHECK: llvm.func @__ocml_tanh_f64(f64) -> f64416 // CHECK-LABEL: func @math_tanh417 func.func @math_tanh(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {418 %result16 = math.tanh %arg_f16 : f16419 // CHECK: llvm.call @__ocml_tanh_f16(%{{.*}}) : (f16) -> f16420 %result32 = math.tanh %arg_f32 : f32421 // CHECK: llvm.call @__ocml_tanh_f32(%{{.*}}) : (f32) -> f32422 %result64 = math.tanh %arg_f64 : f64423 // CHECK: llvm.call @__ocml_tanh_f64(%{{.*}}) : (f64) -> f64424 func.return %result16, %result32, %result64 : f16, f32, f64425 }426}427 428// -----429 430module @test_module {431 // CHECK: llvm.func @__ocml_tan_f16(f16) -> f16432 // CHECK: llvm.func @__ocml_tan_f32(f32) -> f32433 // CHECK: llvm.func @__ocml_tan_f64(f64) -> f64434 // CHECK-LABEL: func @math_tan435 func.func @math_tan(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {436 %result16 = math.tan %arg_f16 : f16437 // CHECK: llvm.call @__ocml_tan_f16(%{{.*}}) : (f16) -> f16438 %result32 = math.tan %arg_f32 : f32439 // CHECK: llvm.call @__ocml_tan_f32(%{{.*}}) : (f32) -> f32440 %result64 = math.tan %arg_f64 : f64441 // CHECK: llvm.call @__ocml_tan_f64(%{{.*}}) : (f64) -> f64442 func.return %result16, %result32, %result64 : f16, f32, f64443 }444}445 446// -----447 448module @test_module {449 // CHECK: llvm.func @__ocml_erf_f16(f16) -> f16450 // CHECK: llvm.func @__ocml_erf_f32(f32) -> f32451 // CHECK: llvm.func @__ocml_erf_f64(f64) -> f64452 // CHECK-LABEL: func @math_erf453 func.func @math_erf(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {454 %result16 = math.erf %arg_f16 : f16455 // CHECK: llvm.call @__ocml_erf_f16(%{{.*}}) : (f16) -> f16456 %result32 = math.erf %arg_f32 : f32457 // CHECK: llvm.call @__ocml_erf_f32(%{{.*}}) : (f32) -> f32458 %result64 = math.erf %arg_f64 : f64459 // CHECK: llvm.call @__ocml_erf_f64(%{{.*}}) : (f64) -> f64460 func.return %result16, %result32, %result64 : f16, f32, f64461 }462}463 464// -----465 466module @test_module {467 // CHECK: llvm.func @__ocml_erfc_f16(f16) -> f16468 // CHECK: llvm.func @__ocml_erfc_f32(f32) -> f32469 // CHECK: llvm.func @__ocml_erfc_f64(f64) -> f64470 // CHECK-LABEL: func @math_erfc471 func.func @math_erfc(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {472 %result16 = math.erfc %arg_f16 : f16473 // CHECK: llvm.call @__ocml_erfc_f16(%{{.*}}) : (f16) -> f16474 %result32 = math.erfc %arg_f32 : f32475 // CHECK: llvm.call @__ocml_erfc_f32(%{{.*}}) : (f32) -> f32476 %result64 = math.erfc %arg_f64 : f64477 // CHECK: llvm.call @__ocml_erfc_f64(%{{.*}}) : (f64) -> f64478 func.return %result16, %result32, %result64 : f16, f32, f64479 }480}481 482// -----483 484module @test_module {485 // CHECK: llvm.func @__ocml_sin_f16(f16) -> f16486 // CHECK: llvm.func @__ocml_sin_f32(f32) -> f32487 // CHECK: llvm.func @__ocml_sin_f64(f64) -> f64488 // CHECK-LABEL: func @math_casting489 func.func @math_casting(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64, %arg_bf16 : bf16) -> (f16, f32, f64, bf16) {490 %resultf16 = math.sin %arg_f16 : f16491 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16492 %resultf32 = math.sin %arg_f32 : f32493 // CHECK: llvm.call @__ocml_sin_f32(%{{.*}}) : (f32) -> f32494 %resultf64 = math.sin %arg_f64 : f64495 // CHECK: llvm.call @__ocml_sin_f64(%{{.*}}) : (f64) -> f64496 %resultbf16 = math.sin %arg_bf16 : bf16497 // CHECK: llvm.fpext %{{.*}} : bf16 to f32498 // CHECK-NEXT: llvm.call @__ocml_sin_f32(%{{.*}}) : (f32) -> f32499 // CHECK-NEXT: llvm.fptrunc %{{.*}} : f32 to bf16500 func.return %resultf16, %resultf32, %resultf64, %resultbf16 : f16, f32, f64, bf16501 }502}503 504// -----505 506module @test_module {507 // CHECK: llvm.func @__ocml_pown_f16(f16, i32) -> f16508 // CHECK: llvm.func @__ocml_pown_f32(f32, i32) -> f32509 // CHECK: llvm.func @__ocml_pown_f64(f64, i32) -> f64510 // CHECK-LABEL: func @math_fpowi511 func.func @math_fpowi(%arg0: f16, %arg1: f32, %arg2: f64, %arg3: i32) -> (f16, f32, f64) {512 // CHECK: llvm.call @__ocml_pown_f16(%{{.*}}) : (f16, i32) -> f16513 %0 = math.fpowi %arg0, %arg3 : f16, i32514 // CHECK: llvm.call @__ocml_pown_f32(%{{.*}}) : (f32, i32) -> f32515 %1 = math.fpowi %arg1, %arg3 : f32, i32516 // CHECK: llvm.call @__ocml_pown_f64(%{{.*}}) : (f64, i32) -> f64517 %2 = math.fpowi %arg2, %arg3 : f64, i32518 return %0, %1, %2 : f16, f32, f64519 }520}521 522// -----523 524// Math operation not inside function525// Ensure it not crash526 527module {528 "test.some_op_with_region"() ({529 ^bb0(%arg0: f64):530 // CHECK: math.atan531 %0 = math.atan %arg0 : f64532 "test.possible_terminator"() : () -> ()533 }) : () -> ()534}535 536// -----537 538module @test_module {539 // CHECK: llvm.func @__ocml_sin_f16(f16) -> f16540 // CHECK-LABEL: func @math_sin_vector_0d541 func.func @math_sin_vector_0d(%arg : vector<f16>) -> vector<f16> {542 // CHECK: llvm.extractelement {{.*}} : vector<1xf16>543 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16544 // CHECK: llvm.insertelement {{.*}} : vector<1xf16>545 %result = math.sin %arg : vector<f16>546 func.return %result : vector<f16>547 }548}549 550// -----551 552module @test_module {553 // CHECK: llvm.func @__ocml_sin_f16(f16) -> f16554 // CHECK-LABEL: func @math_sin_vector_1d555 func.func @math_sin_vector_1d(%arg : vector<4xf16>) -> vector<4xf16> {556 // CHECK: llvm.extractelement {{.*}} : vector<4xf16>557 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16558 // CHECK: llvm.insertelement {{.*}} : vector<4xf16>559 // CHECK: llvm.extractelement {{.*}} : vector<4xf16>560 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16561 // CHECK: llvm.insertelement {{.*}} : vector<4xf16>562 // CHECK: llvm.extractelement {{.*}} : vector<4xf16>563 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16564 // CHECK: llvm.insertelement {{.*}} : vector<4xf16>565 // CHECK: llvm.extractelement {{.*}} : vector<4xf16>566 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16567 // CHECK: llvm.insertelement {{.*}} : vector<4xf16>568 %result = math.sin %arg : vector<4xf16>569 func.return %result : vector<4xf16>570 }571}572 573// -----574 575module @test_module {576 // CHECK: llvm.func @__ocml_sin_f16(f16) -> f16577 // CHECK-LABEL: func @math_sin_vector_2d578 func.func @math_sin_vector_2d(%arg : vector<2x2xf16>) -> vector<2x2xf16> {579 // CHECK: builtin.unrealized_conversion_cast {{.*}} : vector<2x2xf16> to !llvm.array<2 x vector<2xf16>>580 // CHECK: llvm.extractvalue {{.*}} : !llvm.array<2 x vector<2xf16>>581 // CHECK: llvm.extractelement {{.*}} : vector<2xf16>582 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16583 // CHECK: llvm.insertelement {{.*}} : vector<2xf16>584 // CHECK: llvm.extractelement {{.*}} : vector<2xf16>585 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16586 // CHECK: llvm.insertelement {{.*}} : vector<2xf16>587 // CHECK: llvm.insertvalue {{.*}} : !llvm.array<2 x vector<2xf16>>588 // CHECK: llvm.extractvalue {{.*}} : !llvm.array<2 x vector<2xf16>>589 // CHECK: llvm.extractelement {{.*}} : vector<2xf16>590 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16591 // CHECK: llvm.insertelement {{.*}} : vector<2xf16>592 // CHECK: llvm.extractelement {{.*}} : vector<2xf16>593 // CHECK: llvm.call @__ocml_sin_f16(%{{.*}}) : (f16) -> f16594 // CHECK: llvm.insertelement {{.*}} : vector<2xf16>595 // CHECK: llvm.insertvalue {{.*}} : !llvm.array<2 x vector<2xf16>> 596 %result = math.sin %arg : vector<2x2xf16>597 func.return %result : vector<2x2xf16>598 }599}600 601// -----602 603// f16 clamp → rocdl.fmed3 on gfx9+604// CHECK-LABEL: func.func @clampf_f16605func.func @clampf_f16(%x: f16, %lo: f16, %hi: f16) -> f16 {606 %r = math.clampf %x to [%lo, %hi] : f16607 return %r : f16608 // POST9: rocdl.fmed3 {{.*}} : f16609 // PRE9-NOT: rocdl.fmed3610 // PRE9: math.clampf {{.*}} : f16611}612 613// f32 clamp → rocdl.fmed3 on gfx9+614// CHECK-LABEL: func.func @clampf_f32615func.func @clampf_f32(%x: f32, %lo: f32, %hi: f32) -> f32 {616 %r = math.clampf %x to [%lo, %hi] : f32617 return %r : f32618 // POST9: rocdl.fmed3 {{.*}} : f32619 // PRE9-NOT: rocdl.fmed3620 // PRE9: math.clampf {{.*}} : f32621}622 623// -----624 625// Vector f16 clamp → rocdl.fmed3 on gfx9+626// CHECK-LABEL: func.func @clampf_vector_f16627func.func @clampf_vector_f16(%x: vector<2xf16>, %lo: vector<2xf16>, %hi: vector<2xf16>) -> vector<2xf16> {628 %r = math.clampf %x to [%lo, %hi] : vector<2xf16>629 return %r : vector<2xf16>630 // POST9: rocdl.fmed3 {{.*}} : vector<2xf16>631 // PRE9-NOT: rocdl.fmed3632 // PRE9: math.clampf {{.*}} : vector<2xf16>633}634 635// -----636 637// Vector f32 clamp → rocdl.fmed3 on gfx9+638// CHECK-LABEL: func.func @clampf_vector_f32639func.func @clampf_vector_f32(%x: vector<2xf32>, %lo: vector<2xf32>, %hi: vector<2xf32>) -> vector<2xf32> {640 %r = math.clampf %x to [%lo, %hi] : vector<2xf32>641 return %r : vector<2xf32>642 // POST9: rocdl.fmed3 {{.*}} : vector<2xf32>643 // PRE9-NOT: rocdl.fmed3644 // PRE9: math.clampf {{.*}} : vector<2xf32>645}646 647// -----648 649// Multi-dimensional vector f16 clamp → rocdl.fmed3 on gfx9+ (unrolled to 1D vectors)650// CHECK-LABEL: func.func @clampf_vector_2d_f16651func.func @clampf_vector_2d_f16(%x: vector<2x2xf16>, %lo: vector<2x2xf16>, %hi: vector<2x2xf16>) -> vector<2x2xf16> {652 %r = math.clampf %x to [%lo, %hi] : vector<2x2xf16>653 return %r : vector<2x2xf16>654 // POST9: builtin.unrealized_conversion_cast {{.*}} : vector<2x2xf16> to !llvm.array<2 x vector<2xf16>>655 // POST9: llvm.extractvalue {{.*}} : !llvm.array<2 x vector<2xf16>>656 // POST9: rocdl.fmed3 {{.*}} : vector<2xf16>657 // POST9: llvm.insertvalue {{.*}} : !llvm.array<2 x vector<2xf16>>658 // POST9: llvm.extractvalue {{.*}} : !llvm.array<2 x vector<2xf16>>659 // POST9: rocdl.fmed3 {{.*}} : vector<2xf16>660 // POST9: llvm.insertvalue {{.*}} : !llvm.array<2 x vector<2xf16>>661 // PRE9-NOT: rocdl.fmed3662 // PRE9: math.clampf {{.*}} : vector<2x2xf16>663}664 665// -----666// CHECK-LABEL: func.func @clampf_bf16667func.func @clampf_bf16(%x: bf16, %lo: bf16, %hi: bf16) -> bf16 {668 %r = math.clampf %x to [%lo, %hi] : bf16669 return %r : bf16670 // CHECK: math.clampf {{.*}} : bf16671 // CHECK-NOT: rocdl.fmed3672}673