summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/Math
AgeCommit message (Collapse)Author
2025-09-02[mlir][math] Add `clampf` and clean math `ExpandOps` API (#151153)Fabian Mora
This patch adds the `clampf` operation to the math dialect. The semantics op are defined as: ``` clampf(x, min_v, max_v) = max(min(x, min_v), max_v) ``` The reasoning behind adding this operation is that some GPU vendors offer specialized intrinsics for this operation, or subsets of this operation. For example, [__saturatef](https://docs.nvidia.com/cuda/cuda-math-api/cuda_math_api/group__CUDA__MATH__INTRINSIC__SINGLE.html#group__cuda__math__intrinsic__single_1ga2c84f08e0db7117a14509d21c3aec04e) in NVIDIA GPUs, or `__builtin_amdgcn_fmed3f` in AMD GPUs. This patch also removes `test-expand-math` in favor of `math-expand-ops`. Finally, it removes individual expansion population API calls like `populateExpandCoshPattern` in favor of: ```C++ void populateExpansionPatterns(RewritePatternSet &patterns, ArrayRef<StringRef> opMnemonics = {}); ```
2025-01-24[mlir] [math] Fix the precision issue of expand math (#120865)donald chen
The convertFloorOp pattern incurs precision loss when floating-point numbers exceed the representable range of int64. This pattern should be removed. Fixes https://github.com/llvm/llvm-project/issues/119836
2025-01-22Reapply "[mlir] Link libraries that aren't included in libMLIR to libMLIR" ↵Michał Górny
(#123910) Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea. I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently. [v3 with more `-DBUILD_SHARED_LIBS=ON` fixes]
2025-01-22Revert "[mlir] Link libraries that aren't included in libMLIR to libMLIR ↵Michał Górny
(#123781)" This reverts commit 4c6242ebf50dde0597df2bace49d534b61122496. More BUILD_SHARED_LIBS=ON regressions, sigh.
2025-01-22[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123781)Michał Górny
Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea. I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently. [v2 with fixed `-DBUILD_SHARED_LIBS=ON` build]
2025-01-20Revert "[mlir] Link libraries that aren't included in libMLIR to libMLIR ↵Michał Górny
(#123477)" This reverts commit af6616676fb7f9dd4898290ea684ee0c90f1701d. It broke builds with `-DBUILD_SHARED_LIBS=ON`.
2025-01-20[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123477)Michał Górny
Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea. I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently.
2024-12-20[mlir] Enable decoupling two kinds of greedy behavior. (#104649)Jacques Pienaar
The greedy rewriter is used in many different flows and it has a lot of convenience (work list management, debugging actions, tracing, etc). But it combines two kinds of greedy behavior 1) how ops are matched, 2) folding wherever it can. These are independent forms of greedy and leads to inefficiency. E.g., cases where one need to create different phases in lowering and is required to applying patterns in specific order split across different passes. Using the driver one ends up needlessly retrying folding/having multiple rounds of folding attempts, where one final run would have sufficed. Of course folks can locally avoid this behavior by just building their own, but this is also a common requested feature that folks keep on working around locally in suboptimal ways. For downstream users, there should be no behavioral change. Updating from the deprecated should just be a find and replace (e.g., `find ./ -type f -exec sed -i 's|applyPatternsAndFoldGreedily|applyPatternsGreedily|g' {} \;` variety) as the API arguments hasn't changed between the two.
2024-05-13[mlir][math] lower rsqrt to sqrt + fdiv (#91344)Corentin Ferry
This commit creates an expansion pattern to lower math.rsqrt(x) into fdiv(1, sqrt(x)).
2024-05-07[mlir][math] Add expand patterns for acosh, asinh, atanh (#90718)jinchen
2024-04-01[mlir][math] Expand powfI operation for constant power operand. (#87081)Prashant Kumar
-- Convert `math.fpowi` to a series of `arith.mulf` operations. -- If the power is negative, we divide the result by 1.
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-04-22Revert "Revert "Fix handling of special and large vals in expand pattern for ↵Ramiro Leal-Cavazos
`round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith"" This reverts commit 87cef78fa1c7bf6efc544e990894a6062d56abec. The issue in the original revert is that a lit test expecting a `-nan` as an output was failing on M2. Since the IEEE 754-2008 standard does not require the sign to be printed when displaying a `nan`, this commit changes the `CHECK` for `-nan` to one that checks the result value bitcasted to an `i32` to ensure that input is being left unchanged. This check should now be independent of platform being used to run test. Reviewed By: jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D148941
2023-04-21Revert "Fix handling of special and large vals in expand pattern for ↵Mehdi Amini
`round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith" This reverts commit 8d2bae9abdc30e104bab00a4dd0f9d39f5bdda6e and commit ab2fc9521ec606603412645d4a4b3cf456acd153. Tests are broken on Mac M2
2023-04-20Add pattern that expands `math.roundeven` into `math.round` + arithRamiro Leal-Cavazos
This commit adds a pattern that expands `math.roundeven` into `math.round` + some ops from `arith`. This is needed to be able to run `math.roundeven` in a vectorized manner. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D148285
2023-04-14[mlir][math] Expand math.powf to exp, log and multiplyBalaji V. Iyer
Powf functions are pushed directly to libm. This is problematic for situations where libm is not available. This patch will decompose the powf function into log of exponent multiplied by log of base and raise it to the exp. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D148164
2023-04-13[mlir][math] Expand math.round to truncate, compare and increment.Balaji V. Iyer
Round functions are pushed directly to libm. This is problematic for situations where libm is not available. This patch will decompose the roundf function by adding 0.5 to positive number to input (subtracting for negative) following by a truncate. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D148026
2023-04-13[mlir][math] Expand math.exp2 to use math.exp.Balaji V. Iyer
Exp2 functions are pushed directly to libm. This is problematic for situations where libm is not available. This patch will expand the exp2 function to use exp2 with the input multiplied by ln2 (natural log). Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D148064
2023-04-11[mlir][math] Expand math.ceilf to truncate, compares and incrementsBalaji V. Iyer
Ceilf are pushed directly to libm. This is problematic for situations where libm is not available. This patch will break down a ceilf function to truncate followed by an increment if the truncated value is smaller than the input value. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D147974
2023-04-10[mlir][math] Expand math.floorf to truncate, compares and incrementsBalaji V. Iyer
Floorf are pushed directly to libm. This is problematic for situations where libm is not available. This patch will break down a floorf function to truncate followed by an increment for negative values, if necessary. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D147966
2023-04-07[mlir][math]Expand Fused math.fmaf to a multiply-addBalaji V. Iyer
Fused multiply and add are being pushed directly to the libm. This is problematic for situations where libm is not available. This patch will break down a fused multiply and add into a multiply followed by an add. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D147811
2023-04-06[mlir][math] Update math arith expansions for vectorizationRobert Suderman
The math arithmetic expansions do not support vectorized types. Updated the lowerings so that they support vectorized types. This includes a different implementation for `math.ctlz` to be a binary search and not have variable termination time. Reviewed By: jpienaar, NatashaKnk Differential Revision: https://reviews.llvm.org/D147289
2023-03-01[mlir][math] Math expansion for math.tanRobert Suderman
We can implement a polynomial approximation of math.tan by decomposing to `math.sin` and `math.cos`. While it is not technically a polynomial approximation it should be the most straight forward approximation. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D144980
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-06-20[mlir] move SCF headers to SCF/{IR,Transforms} respectivelyAlex Zinenko
This aligns the SCF dialect file layout with the majority of the dialects. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D128049
2022-06-13[mlir] (NFC) Clean up bazel and CMake target namesMogball
All dialect targets in bazel have been named *Dialect and all dialect targets in CMake have been named MLIR*Dialect.
2022-06-01[mlir][math] Add math.ctlz expansion to control flow + arith operationsRob Suderman
Ctlz is an intrinsic in LLVM but does not have equivalent operations in SPIR-V. Including a decomposition gives an alternative path for these platforms. Reviewed By: NatashaKnk Differential Revision: https://reviews.llvm.org/D126261
2022-04-04[mlir] Rework the implementation of TypeIDRiver Riddle
This commit restructures how TypeID is implemented to ideally avoid the current problems related to shared libraries. This is done by changing the "implicit" fallback path to use the name of the type, instead of using a static template variable (which breaks shared libraries). The major downside to this is that it adds some additional initialization costs for the implicit path. Given the use of type names for uniqueness in the fallback, we also no longer allow types defined in anonymous namespaces to have an implicit TypeID. To simplify defining an ID for these classes, a new `MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` macro was added to allow for explicitly defining a TypeID directly on an internal class. To help identify when types are using the fallback, `-debug-only=typeid` can be used to log which types are using implicit ids. This change generally only requires changes to the test passes, which are all defined in anonymous namespaces, and thus can't use the fallback any longer. Differential Revision: https://reviews.llvm.org/D122775
2022-03-08[mlir][test] Generalize a bunch of FuncOp based passes to run on any ↵River Riddle
operation/interfaces A lot of test passes are currently anchored on FuncOp, but this dependency is generally just historical. A majority of these test passes can run on any operation, or can operate on a specific interface (FunctionOpInterface/SymbolOpInterface). This allows for greatly reducing the API dependency on FuncOp, which is slated to be moved out of the Builtin dialect. Differential Revision: https://reviews.llvm.org/D121191
2022-01-31[mlir][vector][NFC] Split into IR, Transforms and UtilsMatthias Springer
This reduces the dependencies of the MLIRVector target and makes the dialect consistent with other dialects. Differential Revision: https://reviews.llvm.org/D118533
2022-01-18[mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>River Riddle
The only benefit of FunctionPass is that it filters out function declarations. This isn't enough to justify carrying it around, as we can simplify filter out declarations when necessary within the pass. We can also explore with better scheduling primitives to filter out declarations at the pipeline level in the future. The definition of FunctionPass is left intact for now to allow time for downstream users to migrate. Differential Revision: https://reviews.llvm.org/D117182
2022-01-02Apply clang-tidy fixes for bugprone-copy-constructor-init to MLIR (NFC)Mehdi Amini
Reviewed By: rriddle, Mogball Differential Revision: https://reviews.llvm.org/D116245
2021-12-20Fix clang-tidy issues in mlir/ (NFC)Mehdi Amini
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115956
2021-12-08Adjust "end namespace" comment in MLIR to match new agree'd coding styleMehdi Amini
See D115115 and this mailing list discussion: https://lists.llvm.org/pipermail/llvm-dev/2021-December/154199.html Differential Revision: https://reviews.llvm.org/D115309
2021-10-23[mlir] Add polynomial approximation for vectorized math::RsqrtEmilio Cota
This patch adds a polynomial approximation that matches the approximation in Eigen. Note that the approximation only applies to vectorized inputs; the scalar rsqrt is left unmodified. The approximation is protected with a flag since it emits an AVX2 intrinsic (generated via the X86Vector). This is the only reasonably clean way that I could find to generate the exact approximation that I wanted (i.e. an identical one to Eigen's). I considered two alternatives: 1. Introduce a Rsqrt intrinsic in LLVM, which doesn't exist yet. I believe this is because there is no definition of Rsqrt that all backends could agree on, since hardware instructions that implement it have widely varying degrees of precision. This is something that the standard could mandate, but Rsqrt is not part of IEEE754, so I don't think this option is feasible. 2. Emit fdiv(1.0, sqrt) with fast math flags to allow reciprocal transformations. Although portable, this doesn't allow us to generate exactly the code we want; it is the LLVM backend, and not MLIR, who controls what code is generated based on the target CPU. Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D112192
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-08-13[mlir] Remove unused header include.Adrian Kuegel
Also adjust BUILD.bazel and remove an unused dependency. Differential Revision: https://reviews.llvm.org/D108027
2021-08-12[mlir] Drop LLVM dialect from TestPolynomialApproximationBenjamin Kramer
No longer needed after c1ebefdf77f34cc0b23597071098c8f8a8d2839b
2021-08-11Add missing cmake dep to fix MLIR build with BUILD_SHARED_LIBS=ON (NFC)Mehdi Amini
2021-07-27[mlir] Math: add algebraic simplification patterns to math transformsEugene Zhulenev
Reviewed By: bkramer Differential Revision: https://reviews.llvm.org/D106822
2021-06-16Migrate MLIR test passes to the new registration APIMehdi Amini
Make sure they all define getArgument()/getDescription(). Depends On D104421 Differential Revision: https://reviews.llvm.org/D104426
2021-05-14[mlir][NFC] Move passes in test/lib/Transforms/ to a directory that mirrors ↵River Riddle
what they test test/lib/Transforms/ has bitrot and become somewhat of a dumping grounds for testing pretty much any part of the project. This revision cleans this up, and moves the files within to a directory that reflects what is actually being tested. Differential Revision: https://reviews.llvm.org/D102456