Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen] Change SignBitOp result type to !cir.bool #1187

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
}

cir::SignBitOp createSignBit(mlir::Location loc, mlir::Value val) {
auto resTy = cir::IntType::get(getContext(), 32, true);
auto resTy = cir::BoolType::get(getContext());
return create<cir::SignBitOp>(loc, resTy, val);
}

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -5274,11 +5274,11 @@ def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg",
def SignBitOp : CIR_Op<"signbit", [Pure]> {
let summary = "Checks the sign of a floating-point number";
let description = [{
It returns a non-zero value (true) if the number is negative
and zero (false) if the number is positive or zero.
It returns true if the number is negative
and false if the number is positive or zero.
PikachuHyA marked this conversation as resolved.
Show resolved Hide resolved
}];
let arguments = (ins CIR_AnyFloat:$input);
let results = (outs SInt32:$res);
let results = (outs CIR_BoolType:$res);
let assemblyFormat = [{
$input attr-dict `:` type($input) `->` qualified(type($res))
}];
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3832,8 +3832,7 @@ mlir::LogicalResult CIRToLLVMSignBitOpLowering::matchAndRewrite(
auto cmpResult = rewriter.create<mlir::LLVM::ICmpOp>(
op.getLoc(), mlir::LLVM::ICmpPredicate::slt, bitcast.getResult(), zero);
auto converted = rewriter.create<mlir::LLVM::ZExtOp>(
op.getLoc(), mlir::IntegerType::get(rewriter.getContext(), 32),
cmpResult);
op.getLoc(), getTypeConverter()->convertType(op.getType()), cmpResult);
rewriter.replaceOp(op, converted);
return mlir::success();
}
Expand Down
15 changes: 6 additions & 9 deletions clang/test/CIR/CodeGen/builtin-signbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@

void test_signbit_float(float val) {
// CIR-LABEL: test_signbit_float
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.float -> !s32i
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.float -> !cir.bool
// LLVM-LABEL: test_signbit_float
// LLVM: [[TMP1:%.*]] = bitcast float %{{.+}} to i32
// LLVM: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
// LLVM: %{{.+}} = zext i1 [[TMP2]] to i32
__builtin_signbit(val);
if (__builtin_signbit(val)) {};
}

void test_signbit_double(double val) {
// CIR-LABEL: test_signbit_double
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.float -> !s32i
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.float -> !cir.bool
// LLVM-LABEL: test_signbit_double
// LLVM: [[CONV:%.*]] = fptrunc double %{{.+}} to float
// LLVM: [[TMP1:%.*]] = bitcast float [[CONV]] to i32
// LLVM: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
// LLVM: %{{.+}} = zext i1 [[TMP2]] to i32
__builtin_signbitf(val);
if (__builtin_signbitf(val)) {}
}

void test_signbit_long_double(long double val) {
// CIR: test_signbit_long_double
// LLVM: test_signbit_long_double
__builtin_signbitl(val);
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.long_double<!cir.f80> -> !s32i
if (__builtin_signbitl(val)) {}
// CIR: %{{.+}} = cir.signbit %{{.+}} : !cir.long_double<!cir.f80> -> !cir.bool
// LLVM: [[TMP1:%.*]] = bitcast x86_fp80 %{{.+}} to i80
// LLVM: [[TMP2:%.*]] = icmp slt i80 [[TMP1]], 0
// LLVM: %{{.+}} = zext i1 [[TMP2]] to i32
}
Loading