[llvm-branch-commits] [mlir] e04785b - [mlir] Add NVVM lowering for std.pow

Tres Popp via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 15 09:34:02 PST 2020


Author: Tres Popp
Date: 2020-12-15T18:28:23+01:00
New Revision: e04785b131cda100f1aab38067a36ae60c7d5680

URL: https://github.com/llvm/llvm-project/commit/e04785b131cda100f1aab38067a36ae60c7d5680
DIFF: https://github.com/llvm/llvm-project/commit/e04785b131cda100f1aab38067a36ae60c7d5680.diff

LOG: [mlir] Add NVVM lowering for std.pow

Differential Revision: https://reviews.llvm.org/D93303

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 a8b4d074a08e..cea1cdc7e25f 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -148,7 +148,7 @@ void mlir::configureGpuToNVVMConversionLegality(ConversionTarget &target) {
   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::SqrtOp>();
+                      LLVM::PowOp, LLVM::SinOp, LLVM::SqrtOp>();
 
   // TODO: Remove once we support replacing non-root ops.
   target.addLegalOp<gpu::YieldOp, gpu::GPUModuleOp, gpu::ModuleEndOp>();
@@ -191,6 +191,8 @@ void mlir::populateGpuToNVVMConversionPatterns(
                                                  "__nv_log10");
   patterns.insert<OpToFuncCallLowering<Log2Op>>(converter, "__nv_log2f",
                                                 "__nv_log2");
+  patterns.insert<OpToFuncCallLowering<PowFOp>>(converter, "__nv_powf",
+                                                "__nv_pow");
   patterns.insert<OpToFuncCallLowering<RsqrtOp>>(converter, "__nv_rsqrtf",
                                                  "__nv_rsqrt");
   patterns.insert<OpToFuncCallLowering<SinOp>>(converter, "__nv_sinf",

diff  --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index d8c4d7e064e5..af6766bba6f4 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -394,3 +394,17 @@ gpu.module @test_module {
   }) : () -> ()
 }
 
+// -----
+
+gpu.module @test_module {
+  // CHECK: llvm.func @__nv_powf(!llvm.float) -> !llvm.float
+  // CHECK: llvm.func @__nv_pow(!llvm.double) -> !llvm.double
+  // CHECK-LABEL: func @gpu_pow
+  func @gpu_pow(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+    %result32 = std.pow %arg_f32, %arg_f32 : f32
+    // CHECK: llvm.call @__nv_powf(%{{.*}}, %{{.*}}) : (!llvm.float) -> !llvm.float
+    %result64 = std.pow %arg_f64, %arg_f64 : f64
+    // CHECK: llvm.call @__nv_pow(%{{.*}}, %{{.*}}) : (!llvm.double) -> !llvm.double
+    std.return %result32, %result64 : f32, f64
+  }
+}


        


More information about the llvm-branch-commits mailing list