summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Math/IR/MathOps.cpp
AgeCommit message (Collapse)Author
2025-09-30[MLIR] Add sincos op to math dialect (#160772)Asher Mancinelli
Now that `sincos` is a supported intrinsic in the LLVM dialect (#160561) we are able to add the corresponding operation in the math dialect and add conversion patterns for LLVM and NVVM. We have several benchmarks that use sine and cosine in hot-loops, and saving some calculations by performing them together can benefit performance. We would like to have a way to represent sincos in the math dialect.
2025-07-22[mlir][NFC] update `mlir/Dialect` create APIs (19/n) (#149926)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-02-20[MLIR][Math] Add floating point value folders (#127947)William Moses
2025-02-18[MLIR][Math] Add erfc to math dialect (#126439)Jan Leyonberg
This patch adds the erfc op to the math dialect. It also does lowering of the math.erfc op to libm calls. There is also a f32 polynomial approximation for the function based on https://stackoverflow.com/questions/35966695/vectorizable-implementation-of-complementary-error-function-erfcf This is in turn based on M. M. Shepherd and J. G. Laframboise, "Chebyshev Approximation of (1+2x)exp(x^2)erfc x in 0 <= x < INF", Mathematics of Computation, Vol. 36, No. 153, January 1981, pp. 249-253. The code has a ULP error less than 3, which was tested, and MLIR test values were verified against the C implementation.
2025-02-16[mlir] add some FP classification ops and their lowering to libdevice (#127322)Oleksandr "Alex" Zinenko
Introduce a subset of floating point classification ops to the Math dialect. These ops mirror functions provided by the C math library and, similarly to the existing `math.copysign`, belong to the math dialect. Add a lowering of those ops to Nvidia libdevice calls when possible as the first mechanism to exercise them.
2024-01-10[mlir][math] Add math.acosh|asin|asinh|atanh op (#77463)Vivek Khandelwal
Signed-Off By: Vivek Khandelwal <vivekkhandelwal1424@gmail.com>
2023-12-15[mlir][math] Added `math.sinh` with expansions to `math.exp` (#75517)Rob Suderman
Includes end-to-end tests for the cpu running, folders using `libm` and lowerings to the corresponding `libm` operations.
2023-12-13Add cosh op to the math dialect. (#75153)Sungsoon Cho
2023-12-08Implement acos operator in MLIR Math Dialect (#74584)Frederik Harwath
Required for torch-mlir. Cf. llvm/torch-mlir#2604 "Implement torch.aten.acos".
2023-09-07[mlir][ub] Add poison support to CommonFolders.hIvan Butygin
Return poison from foldBinary/unary if argument(s) is poison. Add ub dialect as dependency to affected dialects (arith, math, spirv, shape). Add poison materialization to dialects. Add tests for some ops from each dialect. Not all affected ops are covered as it will involve a huge copypaste. Differential Revision: https://reviews.llvm.org/D159013
2023-04-20[mlir][arith] Add arith.constant materialization helperRahul Kayaith
This adds `arith::ConstantOp::materialize`, which builds a constant from an attribute and type only if it would result in a valid op. This is useful for dialect `materializeConstant` hooks, and allows for removing the previous `Attribute, Type` builder which was only used during materialization. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D148491
2023-02-19Use APInt::count{l,r}_{zero,one} (NFC)Kazu Hirata
2023-02-19Use APInt::popcount instead of APInt::countPopulation (NFC)Kazu Hirata
This is for consistency with the C++20-style bit manipulation functions in <bit>.
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13[mlir] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-11[mlir][math][NFC] Migrate math dialect to the new fold APIMarkus Böck
See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618 for context Similar to the patch for the arith dialect, the math dialects fold implementations make heavy use of generic fold functions, hence the change being comparatively mechanical and mostly changing the function signature. Differential Revision: https://reviews.llvm.org/D141500
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-09-19[mlir][Math] Add constant folder for ErfOp.jacquesguan
This patch adds constant folder for ErfOp by using erf/erff of libm. Reviewed By: ftynse, Mogball Differential Revision: https://reviews.llvm.org/D134017
2022-09-16[mlir][Math] Add constant folder for SinOp.jacquesguan
This patch adds constant folder for SinOp by using sin/sinf of libm. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D133915
2022-09-09[mlir][Math] Add TruncOp.jacquesguan
This patch adds TruncOp for Math, it returns the operand rounded to the nearest integer not larger in magnitude than the operand. And this patch also adds the correspond llvm intrinsic op. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D133342
2022-09-09[mlir][math] Canonicalization for math.floor opKai Sasaki
Support constant folding for math.floor op as well as math.ceil. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D133398
2022-09-08[mlir][Math] Add constant folder for RoundOp.jacquesguan
This patch uses round/roundf of libm to fold RoundOp of constant. Differential Revision: https://reviews.llvm.org/D133401
2022-09-07[mlir][Math] Fix RoundEven constant folder.jacquesguan
Use roundToIntegral instead roundeven of libm to avoid window build failed. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D133402
2022-09-07[mlir][Math] Add constant folder for RoundEvenOp.jacquesguan
This patch uses roundeven/roundevenf of libm to fold RoundEvenOp of constant. Differential Revision: https://reviews.llvm.org/D133344
2022-09-07[mlir][Math] Add constant folder for CosOp.jacquesguan
This patch adds constant folder for CosOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D131233
2022-08-15[mlir][math] Added constant folding for IPowI operation.Slava Zakharin
Differential Revision: https://reviews.llvm.org/D130389
2022-08-08[mlir][math] Add `math.absi` opJeff Niu
Adds an integer absolute value op to the math dialect. When converting to LLVM, this op is lowered to the LLVM `abs` intrinsic. When converting to SPIRV, this op is lowered to `spv.GL.SAbs`. Depends on D131325 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131327
2022-08-08[mlir][math] Rename math.abs -> math.absfJeff Niu
To make room for introducing `math.absi`. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131325
2022-08-05[mlir][Math] Add constant folder for Atan2Op.jacquesguan
This patch adds constant folder for Atan2Op which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D131050
2022-08-03[mlir][Math] Add constant folder for AtanOp.jacquesguan
This patch adds constant folder for AtanOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130983
2022-08-02[mlir][Math] Add constant folder for TanhOp.jacquesguan
This patch adds constant folder for TanhOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130960
2022-08-02[mlir][Math] Add constant folder for TanOp.jacquesguan
This patch adds constant folder for TanOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130873
2022-08-01[mlir][Math] Add constant folder for ExpM1Op.jacquesguan
This patch adds constant folder for ExpM1Op which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130567
2022-07-26[mlir][Math] Add constant folder for Exp2Op.jacquesguan
This patch adds constant folder for Exp2Op which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130472
2022-07-25[mlir][Math] Add constant folder for ExpOp.jacquesguan
This patch adds constant folder for ExpOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D130318
2022-07-21[mlir][Math] Add constant folder for LogOp.jacquesguan
This patch adds constant folder for LogOp which only supports single and double precision floating-point. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D130148
2022-07-20[mlir][Math] Add constant folder for Log1pOp.jacquesguan
This patch adds constant folder for Log1pOp which only supports single and double precision floating-point. Differential Revision: https://reviews.llvm.org/D129979
2022-07-18[mlir][Math] Add constant folder for Log10Op.jacquesguan
This patch adds constant folder for Log10Op which only support single and double precision floating-point. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D129740
2022-07-12[mlir][Math] Support fold SqrtOp with constant dense.jacquesguan
This patch uses constFoldUnaryOpConditional to replace current folder in order to support constant dense. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D129459
2022-07-11[mlir][Math] Support fold Log2Op with constant dense.jacquesguan
This patch is similar to D129108, it adds a conditional unary constant folder which allow to exit when the constants not meet the fold condition. And use it for Log2Op to make it able to fold the constant dense. Differential Revision: https://reviews.llvm.org/D129251
2022-07-07[mlir][Math] Support fold PowFOp with constant dense.jacquesguan
This patch adds a conditional binary constant folder which allow to exit when the constants not meet the fold condition. And use it for PowFOp to make it able to fold the constant dense. Differential Revision: https://reviews.llvm.org/D129108
2022-04-19Apply clang-tidy fixes for performance-unnecessary-copy-initialization in ↵Mehdi Amini
MathOps.cpp (NFC)
2022-04-12[mlir][Math] Replace some constant folder functions with common folder ↵jacquesguan
functions. Differential Revision: https://reviews.llvm.org/D123485
2022-03-22[mlir][Math] Add more constant folder for Math ops.jacquesguan
This revision add constant folder for abs, copysign, ctlz, cttz and ctpop. Differential Revision: https://reviews.llvm.org/D122115
2022-03-18[mlir][Math] Add constant folder for sqrt.jacquesguan
Differential Revision: https://reviews.llvm.org/D121980
2022-03-17[MLIR][Math] Add constant folder for powfWilliam S. Moses
Constant fold powf, given two constant operands and a compatible type Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D121845
2022-01-14Apply clang-tidy fixes for readability-identifier-naming in MathOps.cpp (NFC)Mehdi Amini
2022-01-12[MLIR][Math] Enable constant folding of opsWilliam S. Moses
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D117085
2022-01-12Revert "[MLIR][Math] Enable constant folding of ops"William S. Moses
This reverts commit 2f8b956ab6e63e57fbaa60749c9ba7752b071993. There is a linker error for mlir-nvidia as seen on https://lab.llvm.org/buildbot/#/builders/61/builds/19939. As it's late for me here, I'm oing to rever this for now to be investigated later.
2022-01-12[MLIR][Math] Enable constant folding of opsWilliam S. Moses
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D117085