From e04785b131cda100f1aab38067a36ae60c7d5680 Mon Sep 17 00:00:00 2001 From: Tres Popp Date: Tue, 15 Dec 2020 17:18:06 +0100 Subject: [PATCH] [mlir] Add NVVM lowering for std.pow Differential Revision: https://reviews.llvm.org/D93303 --- mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp | 4 +++- mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp index a8b4d07..cea1cdc 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(); target.addIllegalOp(); + LLVM::PowOp, LLVM::SinOp, LLVM::SqrtOp>(); // TODO: Remove once we support replacing non-root ops. target.addLegalOp(); @@ -191,6 +191,8 @@ void mlir::populateGpuToNVVMConversionPatterns( "__nv_log10"); patterns.insert>(converter, "__nv_log2f", "__nv_log2"); + patterns.insert>(converter, "__nv_powf", + "__nv_pow"); patterns.insert>(converter, "__nv_rsqrtf", "__nv_rsqrt"); patterns.insert>(converter, "__nv_sinf", diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir index d8c4d7e..af6766b 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 + } +} -- 2.7.4