From 49e6c191004aff1a4c4cbac87bcb96c9ff694534 Mon Sep 17 00:00:00 2001 From: MaheshRavishankar Date: Tue, 12 May 2020 23:04:33 -0700 Subject: [PATCH] [mlir][StandardToLLVM] Add SinOp to LLVM dialect and lowering of std.sin to this op. Differential Revision: https://reviews.llvm.org/D79505 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 + mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp | 2 ++ .../Conversion/StandardToLLVM/standard-to-llvm.mlir | 10 ++++++++++ mlir/test/Dialect/LLVMIR/roundtrip.mlir | 3 +++ 4 files changed, 16 insertions(+) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 73908f417370..3939917da32e 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -788,6 +788,7 @@ def LLVM_LogOp : LLVM_UnaryIntrinsicOp<"log">; def LLVM_Prefetch : LLVM_ZeroResultIntrOp<"prefetch", [0]>, Arguments<(ins LLVM_Type:$addr, LLVM_Type:$rw, LLVM_Type:$hint, LLVM_Type:$cache)>; +def LLVM_SinOp : LLVM_UnaryIntrinsicOp<"sin">; def LLVM_SqrtOp : LLVM_UnaryIntrinsicOp<"sqrt">; // diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp index d2a0cf30dfa5..66fe763d88bd 100644 --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -1315,6 +1315,7 @@ using SignedRemIOpLowering = VectorConvertToLLVMPattern; using SignedShiftRightOpLowering = OneToOneConvertToLLVMPattern; +using SinOpLowering = VectorConvertToLLVMPattern; using SqrtOpLowering = VectorConvertToLLVMPattern; using SubFOpLowering = VectorConvertToLLVMPattern; using SubIOpLowering = VectorConvertToLLVMPattern; @@ -2972,6 +2973,7 @@ void mlir::populateStdToLLVMNonMemoryConversionPatterns( SignedDivIOpLowering, SignedRemIOpLowering, SignedShiftRightOpLowering, + SinOpLowering, SplatOpLowering, SplatNdOpLowering, SqrtOpLowering, diff --git a/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir b/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir index b6bc81311abf..b8ebdfbf35f1 100644 --- a/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir +++ b/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir @@ -30,6 +30,16 @@ func @rsqrt(%arg0 : f32) { // ----- +// CHECK-LABEL: func @sine( +// CHECK-SAME: !llvm.float +func @sine(%arg0 : f32) { + // CHECK: "llvm.intr.sin"(%arg0) : (!llvm.float) -> !llvm.float + %0 = sin %arg0 : f32 + std.return +} + +// ----- + // CHECK-LABEL: func @rsqrt_double( // CHECK-SAME: !llvm.double func @rsqrt_double(%arg0 : f64) { diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir index 8e08d5004d69..79f9078e5677 100644 --- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir +++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir @@ -97,6 +97,9 @@ func @ops(%arg0 : !llvm.i32, %arg1 : !llvm.float) { // CHECK: %29 = llvm.fneg %arg1 : !llvm.float %29 = llvm.fneg %arg1 : !llvm.float +// CHECK: "llvm.intr.sin"(%arg1) : (!llvm.float) -> !llvm.float + %30 = "llvm.intr.sin"(%arg1) : (!llvm.float) -> !llvm.float + // CHECK: llvm.return llvm.return }