Skip to content

[CIR] Support __builtin_elementwise_ceil#204974

Open
FantasqueX wants to merge 1 commit into
llvm:mainfrom
FantasqueX:cir-builtin-elementwise-ceil-1
Open

[CIR] Support __builtin_elementwise_ceil#204974
FantasqueX wants to merge 1 commit into
llvm:mainfrom
FantasqueX:cir-builtin-elementwise-ceil-1

Conversation

@FantasqueX

Copy link
Copy Markdown
Contributor

No description provided.

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Jun 21, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Letu Ren (FantasqueX)

Changes

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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp (+3-3)
  • (modified) clang/test/CIR/CodeGenBuiltins/builtins-elementwise.c (+22)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index a483eb635f0e2..cebc4cc733ece 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -537,9 +537,8 @@ static RValue tryEmitFPMathIntrinsic(CIRGenFunction &cgf, const CallExpr *e,
   case Builtin::BI__builtin_ceilf16:
   case Builtin::BI__builtin_ceill:
   case Builtin::BI__builtin_ceilf128:
-    return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(cgf, *e);
   case Builtin::BI__builtin_elementwise_ceil:
-    return RValue::getIgnored();
+    return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(cgf, *e);
   case Builtin::BIcopysign:
   case Builtin::BIcopysignf:
   case Builtin::BIcopysignl:
@@ -1645,6 +1644,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
     return emitUnaryMaybeConstrainedFPBuiltin<cir::Log10Op>(*this, *e);
   case Builtin::BI__builtin_elementwise_cos:
     return emitUnaryMaybeConstrainedFPBuiltin<cir::CosOp>(*this, *e);
+  case Builtin::BI__builtin_elementwise_ceil:
+    return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(*this, *e);
   case Builtin::BI__builtin_elementwise_floor:
     return emitUnaryMaybeConstrainedFPBuiltin<cir::FloorOp>(*this, *e);
   case Builtin::BI__builtin_elementwise_round:
@@ -1664,7 +1665,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
   case Builtin::BI__builtin_elementwise_fmod:
     return RValue::get(
         emitBinaryMaybeConstrainedFPBuiltin<cir::FModOp>(*this, *e));
-  case Builtin::BI__builtin_elementwise_ceil:
   case Builtin::BI__builtin_elementwise_exp10:
   case Builtin::BI__builtin_elementwise_ldexp:
   case Builtin::BI__builtin_elementwise_pow:
diff --git a/clang/test/CIR/CodeGenBuiltins/builtins-elementwise.c b/clang/test/CIR/CodeGenBuiltins/builtins-elementwise.c
index c04739d737632..8d14a813d61f5 100644
--- a/clang/test/CIR/CodeGenBuiltins/builtins-elementwise.c
+++ b/clang/test/CIR/CodeGenBuiltins/builtins-elementwise.c
@@ -261,6 +261,28 @@ void test_builtin_elementwise_cos(float f, double d, vfloat4 vf4,
   vd4 = __builtin_elementwise_cos(vd4);
 }
 
+void test_builtin_elementwise_ceil(float f, double d, vfloat4 vf4,
+                   vdouble4 vd4) {
+  // CIR-LABEL: test_builtin_elementwise_ceil
+  // LLVM-LABEL: test_builtin_elementwise_ceil
+
+  // CIR: cir.ceil %{{.*}} : !cir.float
+  // LLVM: call float @llvm.ceil.f32(float %{{.*}})
+  f = __builtin_elementwise_ceil(f);
+
+  // CIR: cir.ceil %{{.*}} : !cir.double
+  // LLVM: call double @llvm.ceil.f64(double %{{.*}})
+  d = __builtin_elementwise_ceil(d);
+
+  // CIR: cir.ceil %{{.*}} : !cir.vector<4 x !cir.float>
+  // LLVM: call <4 x float> @llvm.ceil.v4f32(<4 x float> %{{.*}})
+  vf4 = __builtin_elementwise_ceil(vf4);
+
+  // CIR: cir.ceil %{{.*}} : !cir.vector<4 x !cir.double>
+  // LLVM: call <4 x double> @llvm.ceil.v4f64(<4 x double> %{{.*}})
+  vd4 = __builtin_elementwise_ceil(vd4);
+}
+
 void test_builtin_elementwise_floor(float f, double d, vfloat4 vf4,
                    vdouble4 vd4) {
   // CIR-LABEL: test_builtin_elementwise_floor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant