From: Goran Flegar Date: Wed, 11 Jan 2023 18:39:10 +0000 (+0100) Subject: Lower math.tan to __nv_tan[f] / __ocml_tan_f{32|64} X-Git-Tag: upstream/17.0.6~21200 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7fe0d346b3049df6e3950159a5de74438d2737a;p=platform%2Fupstream%2Fllvm.git Lower math.tan to __nv_tan[f] / __ocml_tan_f{32|64} At present math.tan fails to lower for NVVM and ROCDL. Differential Revision: https://reviews.llvm.org/D141505 --- diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp index 5050f6b..fe578f7 100644 --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -294,6 +294,7 @@ void mlir::populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter, "__nv_sqrt"); populateOpPatterns(converter, patterns, "__nv_tanhf", "__nv_tanh"); + populateOpPatterns(converter, patterns, "__nv_tanf", "__nv_tan"); } std::unique_ptr> diff --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp index fead289..0182886 100644 --- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp +++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp @@ -256,6 +256,8 @@ void mlir::populateGpuToROCDLConversionPatterns( "__ocml_sqrt_f64"); populateOpPatterns(converter, patterns, "__ocml_tanh_f32", "__ocml_tanh_f64"); + populateOpPatterns(converter, patterns, "__ocml_tan_f32", + "__ocml_tan_f64"); } std::unique_ptr> diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir index 40035fa..4a7e6f5 100644 --- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir +++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir @@ -344,6 +344,25 @@ gpu.module @test_module { // ----- gpu.module @test_module { + // CHECK: llvm.func @__nv_tanf(f32) -> f32 + // CHECK: llvm.func @__nv_tan(f64) -> f64 + // CHECK-LABEL: func @gpu_tan + func.func @gpu_tan(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) { + %result16 = math.tan %arg_f16 : f16 + // CHECK: llvm.fpext %{{.*}} : f16 to f32 + // CHECK-NEXT: llvm.call @__nv_tanf(%{{.*}}) : (f32) -> f32 + // CHECK-NEXT: llvm.fptrunc %{{.*}} : f32 to f16 + %result32 = math.tan %arg_f32 : f32 + // CHECK: llvm.call @__nv_tanf(%{{.*}}) : (f32) -> f32 + %result64 = math.tan %arg_f64 : f64 + // CHECK: llvm.call @__nv_tan(%{{.*}}) : (f64) -> f64 + func.return %result16, %result32, %result64 : f16, f32, f64 + } +} + +// ----- + +gpu.module @test_module { // CHECK: llvm.func @__nv_tanhf(f32) -> f32 // CHECK: llvm.func @__nv_tanh(f64) -> f64 // CHECK-LABEL: func @gpu_tanh diff --git a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir index 0403cdb..ccf8e47 100644 --- a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir +++ b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir @@ -363,6 +363,21 @@ gpu.module @test_module { // ----- gpu.module @test_module { + // CHECK: llvm.func @__ocml_tan_f32(f32) -> f32 + // CHECK: llvm.func @__ocml_tan_f64(f64) -> f64 + // CHECK-LABEL: func @gpu_tan + func.func @gpu_tan(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) { + %result32 = math.tan %arg_f32 : f32 + // CHECK: llvm.call @__ocml_tan_f32(%{{.*}}) : (f32) -> f32 + %result64 = math.tan %arg_f64 : f64 + // CHECK: llvm.call @__ocml_tan_f64(%{{.*}}) : (f64) -> f64 + func.return %result32, %result64 : f32, f64 + } +} + +// ----- + +gpu.module @test_module { // CHECK: llvm.func @__ocml_tanh_f32(f32) -> f32 // CHECK: llvm.func @__ocml_tanh_f64(f64) -> f64 // CHECK-LABEL: func @gpu_tanh