[Mlir-commits] [mlir] [MLIR][NVVM] Add `nvvm.tanh` OP (PR #199525)

Varad Rahul Kamthe llvmlistbot at llvm.org
Tue May 26 06:59:39 PDT 2026


================
@@ -501,6 +501,30 @@ def NVVM_Ex2Op : NVVM_F32UnaryApproxOp<"ex2"> {
   }];
 }
 
+def NVVM_TanhOp : NVVM_Op<"tanh", [Pure, SameOperandsAndResultType]> {
+  let summary = "Hyperbolic tangent (fast approximation)";
+  let description = [{
+    Computes a fast approximation of the hyperbolic tangent of the input
+    value. Lowers to PTX `tanh.approx.f32` (sm_75+, PTX 7.0+). PTX does not
+    expose an `ftz` modifier for `tanh.approx`, so this op has no `ftz`
+    attribute.
+
+    For more information, see PTX ISA:
+    [tanh](https://docs.nvidia.com/cuda/parallel-thread-execution/#floating-point-instructions-tanh)
+  }];
+  let arguments = (ins F32:$src);
----------------
varadk27 wrote:

`Tanh `has no entry in `IntrinsicsNVVM.td` -- f32 works through the generic `llvm.tanh` intrinsic + `afn` flag, which the NVPTX backend pattern-matches to `tanh.approx.f32` . For f16/f16x2/bf16/bf16x2 , that pattern doesn't exist yet, so MLIR has nothing to lower to.

Would it work to land this MLIR PR with f32 only, then I'll add the NVPTX backend patterns for the other types in a follow-up, and extend the op once that's in?

https://github.com/llvm/llvm-project/pull/199525


More information about the Mlir-commits mailing list