[clang] [CIR] Implement elementwise min/max/minimum/maximum/minnum/maxnum/etc (PR #222481)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 11 06:49:01 PDT 2026


================
@@ -2097,7 +2097,46 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
   case Builtin::BI__builtin_elementwise_maximum:
   case Builtin::BI__builtin_elementwise_minimum:
   case Builtin::BI__builtin_elementwise_maximumnum:
-  case Builtin::BI__builtin_elementwise_minimumnum:
+  case Builtin::BI__builtin_elementwise_minimumnum: {
+    mlir::Location loc = getLoc(e->getExprLoc());
+    mlir::Value op0 = emitScalarExpr(e->getArg(0));
+    mlir::Value op1 = emitScalarExpr(e->getArg(1));
+
+    auto getIntrinName = [&](unsigned builtinID) {
+      switch (builtinID) {
+      case Builtin::BI__builtin_elementwise_min:
+        if (cir::isIntOrVectorOfIntType(op0.getType())) {
+          QualType ty = e->getArg(0)->getType();
+          return ty->hasSignedIntegerRepresentation() ? "smin" : "umin";
+        }
+        return "minnum";
+      case Builtin::BI__builtin_elementwise_max:
+        if (cir::isIntOrVectorOfIntType(op0.getType())) {
+          QualType ty = e->getArg(0)->getType();
+          return ty->hasSignedIntegerRepresentation() ? "smax" : "umax";
+        }
+        return "maxnum";
+      case Builtin::BI__builtin_elementwise_minnum:
+        return "minnum";
+      case Builtin::BI__builtin_elementwise_maxnum:
----------------
erichkeane wrote:

Between having to do the 'fallthrough' and it only applying to the 'end' return, it ends up being pretty worse here.  We 'save' the return, but the extra `fallthrough` attribute/etc breaks up the readability too much.  

So I don't think this is a suggestion we should do.

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


More information about the cfe-commits mailing list