https://github.com/YeonguChoe updated https://github.com/llvm/llvm-project/pull/184091
>From 26ff95d314508d2905498d9dea83c5b85dad9a59 Mon Sep 17 00:00:00 2001 From: Yeongu Choe <[email protected]> Date: Mon, 2 Mar 2026 05:17:33 -0500 Subject: [PATCH 1/2] Update CIROps.td --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 5db68b44c2804..c2634e1c4234a 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -6089,6 +6089,16 @@ def CIR_AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> { let assemblyFormat = "$src ( `min_is_poison` $min_is_poison^ )? `:` type($src) attr-dict"; } +def CIR_SignBitOp : CIR_Op<"signbit", [Pure, AlwaysSpeculatableImplTrait]> { + let summary = "Return true if operand is negative. Otherwise, return false."; + let description = [{ + `cir.signbit` checks the sign of a floating-point number. + }]; + let arguments = (ins CIR_FloatType:$input); + let results = (outs CIR_BoolType:$res); + let assemblyFormat = "$input attr-dict `:` type($input) `->` type($res)"; +} + def CIR_FloorOp : CIR_UnaryFPToFPBuiltinOp<"floor", "FloorOp"> { let summary = "Computes the floating-point floor value"; let description = [{ >From 4162b78a675b23357599f4e462c2f1fce215828c Mon Sep 17 00:00:00 2001 From: YeonguChoe <[email protected]> Date: Fri, 6 Mar 2026 02:17:35 -0500 Subject: [PATCH 2/2] [CIR][CodeGen] Implement __builtin__signbit(x) The signbit CIR generation was implemented, but C/C++ API was not implemented, so I implemented. --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 9 +++- .../CIR/CodeGenBuiltins/builtin-signbit.cpp | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 clang/test/CIR/CodeGenBuiltins/builtin-signbit.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 17056c0edbe0b..8b795ed454d2c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -1822,7 +1822,14 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, case Builtin::BI__scoped_atomic_thread_fence: case Builtin::BI__builtin_signbit: case Builtin::BI__builtin_signbitf: - case Builtin::BI__builtin_signbitl: + case Builtin::BI__builtin_signbitl: { + CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(*this, e); + mlir::Location loc = getLoc(e->getBeginLoc()); + mlir::Value v = emitScalarExpr(e->getArg(0)); + mlir::Value signbit = emitSignBit(loc, *this, v); + return RValue::get( + builder.createBoolToInt(signbit, convertType(e->getType()))); + } case Builtin::BI__warn_memset_zero_len: case Builtin::BI__annotation: case Builtin::BI__builtin_annotation: diff --git a/clang/test/CIR/CodeGenBuiltins/builtin-signbit.cpp b/clang/test/CIR/CodeGenBuiltins/builtin-signbit.cpp new file mode 100644 index 0000000000000..a74914df262d3 --- /dev/null +++ b/clang/test/CIR/CodeGenBuiltins/builtin-signbit.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -fclangir -emit-llvm %s -o %t.cir.ll +// RUN: FileCheck --input-file=%t.cir.ll %s -check-prefix=LLVM +// RUN: %clang_cc1 -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +int test_signbit_float(float x) { + return __builtin_signbit(x); +} +// CIR: cir.signbit %{{.*}} : !cir.float -> !cir.bool +// LLVM: bitcast float {{.*}} to i32 +// LLVM: icmp slt i32 {{.*}}, 0 +// LLVM: zext i1 {{.*}} to i32 +// LLVM: ret i32 + +int test_signbit_double(double x) { + return __builtin_signbit(x); +} +// CIR: cir.signbit %{{.*}} : !cir.double -> !cir.bool +// LLVM: bitcast double {{.*}} to i64 +// LLVM: icmp slt i64 {{.*}}, 0 +// LLVM: zext i1 {{.*}} to i32 +// LLVM: ret i32 + +int test_signbit_long_double(long double x) { + return __builtin_signbit(x); +} +// CIR: cir.signbit %{{.*}} : !cir.long_double<!cir.f80> -> !cir.bool +// LLVM: bitcast x86_fp80 {{.*}} to i80 +// LLVM: icmp slt i80 {{.*}}, 0 +// LLVM: zext i1 {{.*}} to i32 +// LLVM: ret i32 + +int test_signbitf(float x) { + return __builtin_signbitf(x); +} +// CIR: cir.signbit %{{.*}} : !cir.float -> !cir.bool +// LLVM: bitcast float {{.*}} to i32 +// LLVM: icmp slt i32 {{.*}}, 0 +// LLVM: zext i1 {{.*}} to i32 +// LLVM: ret i32 + +int test_signbitl(long double x) { + return __builtin_signbitl(x); +} +// CIR: cir.signbit %{{.*}} : !cir.long_double<!cir.f80> -> !cir.bool +// LLVM: bitcast x86_fp80 {{.*}} to i80 +// LLVM: icmp slt i80 {{.*}}, 0 +// LLVM: zext i1 {{.*}} to i32 +// LLVM: ret i32 \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
