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] support builtin signbit #1033

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

PikachuHyA
Copy link
Collaborator

This patch adds support for the __builtin_signbit intrinsic. The intrinsic requires special handling for PowerPC; however, since ClangIR does not currently support PowerPC, this handling is omitted in this implementation.

@PikachuHyA
Copy link
Collaborator Author

handle PPC fp128

if (Ty->isPPC_FP128Ty()) {
// We want the sign bit of the higher-order double. The bitcast we just
// did works as if the double-double was stored to memory and then
// read as an i128. The "store" will put the higher-order double in the
// lower address in both little- and big-Endian modes, but the "load"
// will treat those bits as a different part of the i128: the low bits in
// little-Endian, the high bits in big-Endian. Therefore, on big-Endian
// we need to shift the high bits down to the low before truncating.
Width >>= 1;
if (CGF.getTarget().isBigEndian()) {
Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width);
V = CGF.Builder.CreateLShr(V, ShiftCst);
}
// We are truncating value in order to extract the higher-order
// double, which we will be using to extract the sign from.
IntTy = llvm::IntegerType::get(C, Width);
V = CGF.Builder.CreateTrunc(V, IntTy);
}

@PikachuHyA
Copy link
Collaborator Author

Copy link
Member

@Lancern Lancern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, some minor nits inline

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIROps.td Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp Outdated Show resolved Hide resolved
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, we still need to track missing PPC support, see comments inline. Thanks for working on this

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp Outdated Show resolved Hide resolved
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, few more comments

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Outdated Show resolved Hide resolved
@bcardosolopes
Copy link
Member

My suggestion is for you to first tackle the non-fp80 case, and add unrecheable for that case, in a follow up PR you tackle all the fp80 related shenenigans in one go. How about that?

@PikachuHyA
Copy link
Collaborator Author

My suggestion is for you to first tackle the non-fp80 case, and add unrecheable for that case, in a follow up PR you tackle all the fp80 related shenenigans in one go. How about that?

Thanks for your suggestion! I agree that it makes sense to tackle the non-fp80 case first.

mlir::dyn_cast<cir::LongDoubleType>(op.getInput().getType())) {
if (mlir::isa<cir::FP80Type>(longDoubleType.getUnderlying())) {
// see https://github.com/llvm/clangir/issues/1057
llvm_unreachable("NYI");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For next rounds: during LLVM lowering we're better off erroring out return op.emitError(...) - I'm gonna merge this anyway now cause I know you're gonna be working on this soon anyways! Thanks for the fixes.

@bcardosolopes bcardosolopes merged commit 15f3e5e into llvm:main Nov 11, 2024
6 checks passed
bcardosolopes pushed a commit that referenced this pull request Nov 13, 2024
follow #1033
handle `LongDoubleType` with `FP80Type`.
@PikachuHyA PikachuHyA deleted the support_signbit branch November 18, 2024 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants