diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -138,7 +138,7 @@ target.addIllegalDialect(); target.addIllegalOp(); + LLVM::Log2Op, LLVM::SinOp, LLVM::SqrtOp>(); target.addIllegalOp(); target.addLegalDialect(); // TODO: Remove once we support replacing non-root ops. @@ -187,6 +187,8 @@ "__nv_rsqrt"); patterns.insert>(converter, "__nv_sinf", "__nv_sin"); + patterns.insert>(converter, "__nv_sqrtf", + "__nv_sqrt"); patterns.insert>(converter, "__nv_tanhf", "__nv_tanh"); } diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir --- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir +++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir @@ -315,6 +315,26 @@ // ----- +gpu.module @test_module { + // CHECK: llvm.func @__nv_sqrtf(!llvm.float) -> !llvm.float + // CHECK: llvm.func @__nv_sqrt(!llvm.double) -> !llvm.double + // CHECK-LABEL: func @gpu_sqrt + func @gpu_sqrt(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) + -> (f16, f32, f64) { + %result16 = std.sqrt %arg_f16 : f16 + // CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float + // CHECK-NEXT: llvm.call @__nv_sqrtf(%{{.*}}) : (!llvm.float) -> !llvm.float + // CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half + %result32 = std.sqrt %arg_f32 : f32 + // CHECK: llvm.call @__nv_sqrtf(%{{.*}}) : (!llvm.float) -> !llvm.float + %result64 = std.sqrt %arg_f64 : f64 + // CHECK: llvm.call @__nv_sqrt(%{{.*}}) : (!llvm.double) -> !llvm.double + std.return %result16, %result32, %result64 : f16, f32, f64 + } +} + +// ----- + // Test that we handled properly operation with SymbolTable other than module op gpu.module @test_module { "test.symbol_scope"() ({