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

Fastcasing llvm builtins #1271

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
31 changes: 24 additions & 7 deletions rir/src/compiler/native/lower_function_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2975,8 +2975,14 @@ void LowerFunctionLLVM::compile() {
break;
}
case blt("anyNA"):
case blt("is.na"):
if (irep == Rep::i32) {
case blt("is.na"): {

auto arg = i->arg(0).val();

if ((irep == Rep::i32 || irep == Rep::f64) &&
!arg->type.maybeNAOrNaN()) {
setVal(i, constant(R_FalseValue, orep));
} else if (irep == Rep::i32) {
setVal(i,
builder.CreateSelect(
builder.CreateICmpEQ(a, c(NA_INTEGER)),
Expand All @@ -2990,7 +2996,9 @@ void LowerFunctionLLVM::compile() {
} else {
done = false;
}

break;
}
case blt("is.object"):
if (irep == Rep::SEXP) {
setVal(i, builder.CreateSelect(
Expand Down Expand Up @@ -4731,13 +4739,22 @@ void LowerFunctionLLVM::compile() {
assert(r1 == Rep::i32);
res = load(arg);
if (!arg->type.isA(RType::logical)) {
res = builder.CreateSelect(
builder.CreateICmpEQ(res, c(NA_INTEGER)),
c(NA_LOGICAL),
builder.CreateSelect(

auto nonNAIntegerToBool = [&]() {
return builder.CreateSelect(
builder.CreateICmpEQ(res, c(0)),
constant(R_FalseValue, t::Int),
constant(R_TrueValue, t::Int)));
constant(R_TrueValue, t::Int));
};

if (arg->type.maybeNAOrNaN()) {

res = builder.CreateSelect(
builder.CreateICmpEQ(res, c(NA_INTEGER)),
c(NA_LOGICAL), nonNAIntegerToBool());
} else {
res = nonNAIntegerToBool();
}
}
}

Expand Down