[flang-commits] [flang] [mlir] [mlir][math] Replace roundeven call by nearbyint call when target does not have C23 features (PR #88687)

Frederik Harwath via flang-commits flang-commits at lists.llvm.org
Mon Apr 15 06:08:15 PDT 2024


================
@@ -185,8 +186,15 @@ void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns) {
   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");
+  if (options.allowC23Features)
+    populatePatternsForOp<math::RoundEvenOp>(patterns, ctx, "roundevenf",
+                                             "roundeven");
+  else if (options.roundingModeIsDefault)
+    populatePatternsForOp<math::RoundEvenOp>(patterns, ctx, "nearbyintf",
+                                             "nearbyint");
+  // Roundeven: using nearbyint (pre-C23) for roundeven requires the
----------------
frederik-h wrote:

I am not really qualified to review those changes, but since you asked for a review, perhaps it helps if I ask a few questions to understand what you are trying to do. I see that you need this for Flang. I suppose that roundeven provides the semantics that you need for Fortran. How is this related to "C23" features? Isn't this a question about what is implemented in your libm? It seems that glibc has implemented this (specifically for Fortran support) for several years, see [here](https://sourceware.org/legacy-ml/libc-alpha/2016-12/msg00791.html). Is it unimplemented on any target that you need?

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


More information about the flang-commits mailing list