Skip to content

Commit 0ec8cf3

Browse files
authored
[CIR][CIRGen] Support __builtin_signbitl (#1117)
follow #1033 handle `LongDoubleType` with `FP80Type`.
1 parent 6666565 commit 0ec8cf3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,8 +4364,11 @@ class CIRSignBitOpLowering : public mlir::OpConversionPattern<cir::SignBitOp> {
43644364
if (auto longDoubleType =
43654365
mlir::dyn_cast<cir::LongDoubleType>(op.getInput().getType())) {
43664366
if (mlir::isa<cir::FP80Type>(longDoubleType.getUnderlying())) {
4367-
// see https://github.com/llvm/clangir/issues/1057
4368-
llvm_unreachable("NYI");
4367+
// If the underlying type of LongDouble is FP80Type,
4368+
// DataLayout::getTypeSizeInBits returns 128.
4369+
// See https://github.com/llvm/clangir/issues/1057.
4370+
// Set the width to 80 manually.
4371+
width = 80;
43694372
}
43704373
}
43714374
auto intTy = mlir::IntegerType::get(rewriter.getContext(), width);

clang/test/CIR/CodeGen/builtin-signbit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ void test_signbit_double(double val) {
2323
// LLVM: %{{.+}} = zext i1 [[TMP2]] to i32
2424
__builtin_signbitf(val);
2525
}
26+
27+
void test_signbit_long_double(long double val) {
28+
// CIR: test_signbit_long_double
29+
// LLVM: test_signbit_long_double
30+
__builtin_signbitl(val);
31+
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.long_double<!cir.f80> -> !s32i
32+
// LLVM: [[TMP1:%.*]] = bitcast x86_fp80 %{{.+}} to i80
33+
// LLVM: [[TMP2:%.*]] = icmp slt i80 [[TMP1]], 0
34+
// LLVM: %{{.+}} = zext i1 [[TMP2]] to i32
35+
}

0 commit comments

Comments
 (0)