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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Sep 30 11:51:36 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-emitc

Author: Colin Cross (colincross)

<details>
<summary>Changes</summary>

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

Fixes #<!-- -->227522.

---
Full diff: https://github.com/llvm/llvm-project/pull/227822.diff


2 Files Affected:

- (modified) mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp (+2-2) 
- (modified) mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir (+4-4) 


``````````diff
diff --git a/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp b/mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
index adf06c139021f..b2a52047822fb 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 0947556e20fb5..3d7d8ac5743f7 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

``````````

</details>


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


More information about the Mlir-commits mailing list