[clang] [CIR] Add math and builtin intrinsics support (PR #175233)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 15 15:55:21 PST 2026


================
@@ -1080,40 +1190,63 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
         convertType(e->getType())));
   }
   case Builtin::BI__builtin_nondeterministic_value:
-  case Builtin::BI__builtin_elementwise_abs:
     return errorBuiltinNYI(*this, e, builtinID);
+  case Builtin::BI__builtin_elementwise_abs: {
+    mlir::Type cirTy = convertType(e->getArg(0)->getType());
+    bool isIntTy = cir::isIntOrVectorOfIntType(cirTy);
+    if (!isIntTy)
+      return emitUnaryFPBuiltin<cir::FAbsOp>(*this, *e);
+    mlir::Value arg = emitScalarExpr(e->getArg(0));
+    mlir::Value result = cir::AbsOp::create(builder, getLoc(e->getExprLoc()),
+                                            arg.getType(), arg, false);
+    return RValue::get(result);
+  }
   case Builtin::BI__builtin_elementwise_acos:
     return emitUnaryFPBuiltin<cir::ACosOp>(*this, *e);
   case Builtin::BI__builtin_elementwise_asin:
     return emitUnaryFPBuiltin<cir::ASinOp>(*this, *e);
   case Builtin::BI__builtin_elementwise_atan:
     return emitUnaryFPBuiltin<cir::ATanOp>(*this, *e);
   case Builtin::BI__builtin_elementwise_atan2:
-  case Builtin::BI__builtin_elementwise_ceil:
+    return emitBinaryFPBuiltin<cir::ATan2Op>(*this, *e);
----------------
andykaylor wrote:

This should go through `emitBinaryMaybeConstrainedFPBuiltin`, as should the other elementwise handlers for any function that could raise an FP exception. It's also not clear to me why these elementwise handlers are with the other builtins for the corresponding functions.

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


More information about the cfe-commits mailing list