[Mlir-commits] [mlir] a80a23e - [mlir][EmitC] lower roundeven to __builtin_roundeven (#227822)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 13 09:46:19 PDT 2026


Author: Colin Cross
Date: 2026-10-13T09:46:13-07:00
New Revision: a80a23e3412b1e306f7ef4607fd76de83b4a736c

URL: https://github.com/llvm/llvm-project/commit/a80a23e3412b1e306f7ef4607fd76de83b4a736c
DIFF: https://github.com/llvm/llvm-project/commit/a80a23e3412b1e306f7ef4607fd76de83b4a736c.diff

LOG: [mlir][EmitC] lower roundeven to __builtin_roundeven (#227822)

std::roundeven doesn't exist, and roundeven was added in C23. Lower
roundeven ops to __builtin_roundeven instead.

Fixes #227522.

Added: 
    

Modified: 
    mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
    mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp b/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
index adf06c139021f4..b2a52047822fb4 100644
--- a/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
+++ b/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
@@ -79,7 +79,7 @@ void mlir::registerConvertMathToEmitCInterface(DialectRegistry &registry) {
 }
 
 // Populates patterns to replace `math` operations with `emitc.call_opaque`,
-// using function names consistent with those in <math.h>.
+// using function names consistent with those in <math.h> or a builtin.
 void mlir::populateConvertMathToEmitCPatterns(
     RewritePatternSet &patterns, emitc::LanguageTarget languageTarget) {
   auto *context = patterns.getContext();
@@ -88,7 +88,7 @@ void mlir::populateConvertMathToEmitCPatterns(
   patterns.insert<LowerToEmitCCallOpaque<math::RoundOp>>(context, "round",
                                                          languageTarget);
   patterns.insert<LowerToEmitCCallOpaque<math::RoundEvenOp>>(
-      context, "roundeven", languageTarget);
+      context, "__builtin_roundeven", emitc::LanguageTarget::c99);
   patterns.insert<LowerToEmitCCallOpaque<math::ExpOp>>(context, "exp",
                                                        languageTarget);
   patterns.insert<LowerToEmitCCallOpaque<math::CosOp>>(context, "cos",

diff  --git a/mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir b/mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir
index 0947556e20fb53..3d7d8ac5743f74 100644
--- a/mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir
+++ b/mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir
@@ -124,10 +124,10 @@ func.func @round(%arg0: f32, %arg1: f64) {
 }
 
 func.func @roundeven(%arg0: f32, %arg1: f64) {
-  // c99: emitc.call_opaque "roundevenf"
-  // c99-NEXT: emitc.call_opaque "roundeven"
-  // cpp11: emitc.call_opaque "std::roundeven"
-  // cpp11-NEXT: emitc.call_opaque "std::roundeven"
+  // c99: emitc.call_opaque "__builtin_roundevenf"
+  // c99-NEXT: emitc.call_opaque "__builtin_roundeven"
+  // cpp11: emitc.call_opaque "__builtin_roundevenf"
+  // cpp11-NEXT: emitc.call_opaque "__builtin_roundeven"
   %0 = math.roundeven %arg0 : f32
   %1 = math.roundeven %arg1 : f64
   return


        


More information about the Mlir-commits mailing list