Skip to content

Commit

Permalink
[mlir] Add missing libm member operations to MathToLibm (llvm#87981)
Browse files Browse the repository at this point in the history
This PR adds support for lowering the following Math operations to
`libm` calls:
* `math.absf` -> `fabsf, fabs`
* `math.exp` -> `expf, exp`
* `math.exp2` -> `exp2f, exp2`
* `math.fma` -> `fmaf, fma`
* `math.log` -> `logf, log`
* `math.log2` -> `log2f, log2`
* `math.log10` -> `log10f, log10`
* `math.powf` -> `powf, pow`
* `math.sqrt` -> `sqrtf, sqrt`

These operations are direct members of `libm`, and do not seem to
require any special manipulations on their operands.
  • Loading branch information
cferry-AMD authored Apr 8, 2024
1 parent e27c373 commit 50b9373
Show file tree
Hide file tree
Showing 2 changed files with 376 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ ScalarOpToLibmCall<Op>::matchAndRewrite(Op op,
void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns) {
MLIRContext *ctx = patterns.getContext();

populatePatternsForOp<math::AbsFOp>(patterns, ctx, "fabsf", "fabs");
populatePatternsForOp<math::AcosOp>(patterns, ctx, "acosf", "acos");
populatePatternsForOp<math::AcoshOp>(patterns, ctx, "acoshf", "acosh");
populatePatternsForOp<math::AsinOp>(patterns, ctx, "asinf", "asin");
Expand All @@ -174,14 +175,22 @@ void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns) {
populatePatternsForOp<math::CosOp>(patterns, ctx, "cosf", "cos");
populatePatternsForOp<math::CoshOp>(patterns, ctx, "coshf", "cosh");
populatePatternsForOp<math::ErfOp>(patterns, ctx, "erff", "erf");
populatePatternsForOp<math::ExpOp>(patterns, ctx, "expf", "exp");
populatePatternsForOp<math::Exp2Op>(patterns, ctx, "exp2f", "exp2");
populatePatternsForOp<math::ExpM1Op>(patterns, ctx, "expm1f", "expm1");
populatePatternsForOp<math::FloorOp>(patterns, ctx, "floorf", "floor");
populatePatternsForOp<math::FmaOp>(patterns, ctx, "fmaf", "fma");
populatePatternsForOp<math::LogOp>(patterns, ctx, "logf", "log");
populatePatternsForOp<math::Log2Op>(patterns, ctx, "log2f", "log2");
populatePatternsForOp<math::Log10Op>(patterns, ctx, "log10f", "log10");
populatePatternsForOp<math::Log1pOp>(patterns, ctx, "log1pf", "log1p");
populatePatternsForOp<math::PowFOp>(patterns, ctx, "powf", "pow");
populatePatternsForOp<math::RoundEvenOp>(patterns, ctx, "roundevenf",
"roundeven");
populatePatternsForOp<math::RoundOp>(patterns, ctx, "roundf", "round");
populatePatternsForOp<math::SinOp>(patterns, ctx, "sinf", "sin");
populatePatternsForOp<math::SinhOp>(patterns, ctx, "sinhf", "sinh");
populatePatternsForOp<math::SqrtOp>(patterns, ctx, "sqrtf", "sqrt");
populatePatternsForOp<math::TanOp>(patterns, ctx, "tanf", "tan");
populatePatternsForOp<math::TanhOp>(patterns, ctx, "tanhf", "tanh");
populatePatternsForOp<math::TruncOp>(patterns, ctx, "truncf", "trunc");
Expand Down
Loading

0 comments on commit 50b9373

Please sign in to comment.