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][Builtin][Neon] Lower neon_vrshrd_n for s64 and u64 #1383

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3836,7 +3836,21 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
}
case NEON::BI__builtin_neon_vrshrd_n_u64:
case NEON::BI__builtin_neon_vrshrd_n_s64: {
llvm_unreachable("NEON::BI__builtin_neon_vrshrd_n_s64 NYI");
cir::IntType IntType = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64
? builder.getUInt64Ty()
: builder.getSInt64Ty();

const StringRef Intrinsic = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64
? "aarch64.neon.urshl"
: "aarch64.neon.srshl";
Ops.push_back(emitScalarExpr(E->getArg(1)));
std::optional<llvm::APSInt> APSInt =
E->getArg(1)->getIntegerConstantExpr(getContext());
assert(APSInt && "Expected argument to be a constant");
int64_t SV = -APSInt->getSExtValue();
Ops[1] = builder.getSInt64(SV, getLoc(E->getExprLoc()));
return emitNeonCall(builder, {IntType, builder.getSInt64Ty()}, Ops,
Intrinsic, IntType, getLoc(E->getExprLoc()));
}
case NEON::BI__builtin_neon_vrsrad_n_u64:
case NEON::BI__builtin_neon_vrsrad_n_s64: {
Expand Down
32 changes: 20 additions & 12 deletions clang/test/CIR/CodeGen/AArch64/neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15209,12 +15209,16 @@ uint64_t test_vshrd_n_u64_3(uint64_t a) {
// LLVM: ret i64 [[SHRD_N]]
}

// NYI-LABEL: @test_vrshrd_n_s64(
// NYI: [[VRSHR_N:%.*]] = call i64 @llvm.aarch64.neon.srshl.i64(i64 %a, i64 -63)
// NYI: ret i64 [[VRSHR_N]]
// int64_t test_vrshrd_n_s64(int64_t a) {
// return (int64_t)vrshrd_n_s64(a, 63);
// }
int64_t test_vrshrd_n_s64(int64_t a) {
return (int64_t)vrshrd_n_s64(a, 63);

// CIR-LABEL: vrshrd_n_s64
// CIR: [[TMP0:%.*]] = cir.llvm.intrinsic "aarch64.neon.srshl" {{.*}}, {{.*}} : (!s64i, !s64i) -> !s64i

// LLVM-LABEL: @test_vrshrd_n_s64(
// LLVM: [[VRSHR_N:%.*]] = call i64 @llvm.aarch64.neon.srshl.i64(i64 %0, i64 -63)
// LLVM: ret i64 [[VRSHR_N]]
}

// NYI-LABEL: @test_vrshr_n_s64(
// NYI: [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
Expand All @@ -15225,12 +15229,16 @@ uint64_t test_vshrd_n_u64_3(uint64_t a) {
// return vrshr_n_s64(a, 1);
// }

// NYI-LABEL: @test_vrshrd_n_u64(
// NYI: [[VRSHR_N:%.*]] = call i64 @llvm.aarch64.neon.urshl.i64(i64 %a, i64 -63)
// NYI: ret i64 [[VRSHR_N]]
// uint64_t test_vrshrd_n_u64(uint64_t a) {
// return (uint64_t)vrshrd_n_u64(a, 63);
// }
uint64_t test_vrshrd_n_u64(uint64_t a) {
return (uint64_t)vrshrd_n_u64(a, 63);

// CIR-LABEL: vrshrd_n_u64
// CIR: [[TMP0:%.*]] = cir.llvm.intrinsic "aarch64.neon.urshl" {{.*}}, {{.*}} : (!u64i, !s64i) -> !u64i

// LLVM-LABEL: @test_vrshrd_n_u64(
// LLVM: [[VRSHR_N:%.*]] = call i64 @llvm.aarch64.neon.urshl.i64(i64 %0, i64 -63)
// LLVM: ret i64 [[VRSHR_N]]
}

// NYI-LABEL: @test_vrshr_n_u64(
// NYI: [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
Expand Down
Loading