Skip to content

Commit 3eeb6b4

Browse files
authored
[CIR][CIRGen][Builtin][Neon] Lower vshrd_n_s64 (#1260)
Lowering `vshrd_n_s64`
1 parent a03b999 commit 3eeb6b4

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,11 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
38253825
return builder.createShiftLeft(Ops[0], amt->getZExtValue());
38263826
}
38273827
case NEON::BI__builtin_neon_vshrd_n_s64: {
3828-
llvm_unreachable("NEON::BI__builtin_neon_vshrd_n_s64 NYI");
3828+
std::optional<llvm::APSInt> amt =
3829+
E->getArg(1)->getIntegerConstantExpr(getContext());
3830+
assert(amt && "Expected argument to be a constant");
3831+
uint64_t bits = std::min(static_cast<uint64_t>(63), amt->getZExtValue());
3832+
return builder.createShiftRight(Ops[0], bits);
38293833
}
38303834
case NEON::BI__builtin_neon_vshrd_n_u64: {
38313835
llvm_unreachable("NEON::BI__builtin_neon_vshrd_n_u64 NYI");

clang/test/CIR/CodeGen/AArch64/neon.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15078,12 +15078,16 @@ int16_t test_vqmovns_s32(int32_t a) {
1507815078
// return (uint64_t)vcaltd_f64(a, b);
1507915079
// }
1508015080

15081-
// NYI-LABEL: @test_vshrd_n_s64(
15082-
// NYI: [[SHRD_N:%.*]] = ashr i64 %a, 1
15083-
// NYI: ret i64 [[SHRD_N]]
15084-
// int64_t test_vshrd_n_s64(int64_t a) {
15085-
// return (int64_t)vshrd_n_s64(a, 1);
15086-
// }
15081+
int64_t test_vshrd_n_s64(int64_t a) {
15082+
return (int64_t)vshrd_n_s64(a, 1);
15083+
15084+
// CIR-LABEL: vshrd_n_s64
15085+
// CIR: {{%.*}} = cir.shift(right, {{%.*}} : !s64i, {{%.*}} : !s64i) -> !s64i
15086+
15087+
// LLVM-LABEL: @test_vshrd_n_s64(
15088+
// LLVM: [[SHRD_N:%.*]] = ashr i64 %0, 1
15089+
// LLVM: ret i64 [[SHRD_N]]
15090+
}
1508715091

1508815092
// NYI-LABEL: @test_vshrd_n_u64(
1508915093
// NYI: ret i64 0

0 commit comments

Comments
 (0)