[llvm-branch-commits] [mlir] b4750f5 - Add sqrt lowering from standard to NVVM
Frederik Gossen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 8 08:13:32 PST 2020
Author: Frederik Gossen
Date: 2020-12-08T17:08:27+01:00
New Revision: b4750f58d89f2fbc74489b5e56d30daadec47198
URL: https://github.com/llvm/llvm-project/commit/b4750f58d89f2fbc74489b5e56d30daadec47198
DIFF: https://github.com/llvm/llvm-project/commit/b4750f58d89f2fbc74489b5e56d30daadec47198.diff
LOG: Add sqrt lowering from standard to NVVM
Differential Revision: https://reviews.llvm.org/D92850
Added:
Modified:
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 4b7bb6e193a4..467c622f8bde 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -138,7 +138,7 @@ struct LowerGpuOpsToNVVMOpsPass
target.addIllegalDialect<gpu::GPUDialect>();
target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::FAbsOp, LLVM::FCeilOp,
LLVM::FFloorOp, LLVM::LogOp, LLVM::Log10Op,
- LLVM::Log2Op, LLVM::SinOp>();
+ LLVM::Log2Op, LLVM::SinOp, LLVM::SqrtOp>();
target.addIllegalOp<FuncOp>();
target.addLegalDialect<NVVM::NVVMDialect>();
// TODO: Remove once we support replacing non-root ops.
@@ -187,6 +187,8 @@ void mlir::populateGpuToNVVMConversionPatterns(
"__nv_rsqrt");
patterns.insert<OpToFuncCallLowering<SinOp>>(converter, "__nv_sinf",
"__nv_sin");
+ patterns.insert<OpToFuncCallLowering<SqrtOp>>(converter, "__nv_sqrtf",
+ "__nv_sqrt");
patterns.insert<OpToFuncCallLowering<TanhOp>>(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
index 347cc48daa20..1c0257de0d55 100644
--- 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 {
// -----
+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"() ({
More information about the llvm-branch-commits
mailing list