Skip to content

Commit 50b9373

Browse files
authored
[mlir] Add missing libm member operations to MathToLibm (#87981)
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.
1 parent e27c373 commit 50b9373

File tree

2 files changed

+376
-0
lines changed

2 files changed

+376
-0
lines changed

mlir/lib/Conversion/MathToLibm/MathToLibm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ ScalarOpToLibmCall<Op>::matchAndRewrite(Op op,
162162
void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns) {
163163
MLIRContext *ctx = patterns.getContext();
164164

165+
populatePatternsForOp<math::AbsFOp>(patterns, ctx, "fabsf", "fabs");
165166
populatePatternsForOp<math::AcosOp>(patterns, ctx, "acosf", "acos");
166167
populatePatternsForOp<math::AcoshOp>(patterns, ctx, "acoshf", "acosh");
167168
populatePatternsForOp<math::AsinOp>(patterns, ctx, "asinf", "asin");
@@ -174,14 +175,22 @@ void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns) {
174175
populatePatternsForOp<math::CosOp>(patterns, ctx, "cosf", "cos");
175176
populatePatternsForOp<math::CoshOp>(patterns, ctx, "coshf", "cosh");
176177
populatePatternsForOp<math::ErfOp>(patterns, ctx, "erff", "erf");
178+
populatePatternsForOp<math::ExpOp>(patterns, ctx, "expf", "exp");
179+
populatePatternsForOp<math::Exp2Op>(patterns, ctx, "exp2f", "exp2");
177180
populatePatternsForOp<math::ExpM1Op>(patterns, ctx, "expm1f", "expm1");
178181
populatePatternsForOp<math::FloorOp>(patterns, ctx, "floorf", "floor");
182+
populatePatternsForOp<math::FmaOp>(patterns, ctx, "fmaf", "fma");
183+
populatePatternsForOp<math::LogOp>(patterns, ctx, "logf", "log");
184+
populatePatternsForOp<math::Log2Op>(patterns, ctx, "log2f", "log2");
185+
populatePatternsForOp<math::Log10Op>(patterns, ctx, "log10f", "log10");
179186
populatePatternsForOp<math::Log1pOp>(patterns, ctx, "log1pf", "log1p");
187+
populatePatternsForOp<math::PowFOp>(patterns, ctx, "powf", "pow");
180188
populatePatternsForOp<math::RoundEvenOp>(patterns, ctx, "roundevenf",
181189
"roundeven");
182190
populatePatternsForOp<math::RoundOp>(patterns, ctx, "roundf", "round");
183191
populatePatternsForOp<math::SinOp>(patterns, ctx, "sinf", "sin");
184192
populatePatternsForOp<math::SinhOp>(patterns, ctx, "sinhf", "sinh");
193+
populatePatternsForOp<math::SqrtOp>(patterns, ctx, "sqrtf", "sqrt");
185194
populatePatternsForOp<math::TanOp>(patterns, ctx, "tanf", "tan");
186195
populatePatternsForOp<math::TanhOp>(patterns, ctx, "tanhf", "tanh");
187196
populatePatternsForOp<math::TruncOp>(patterns, ctx, "truncf", "trunc");

0 commit comments

Comments
 (0)