Skip to content

Commit bd14365

Browse files
ghehglanza
authored andcommitted
[CIR][CIRGen][Builtin][Neon] Lower vcvt_f32_v, vcvtq_f32_v (llvm#1120)
1 parent 4f750e3 commit bd14365

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,7 @@ mlir::Value CIRGenFunction::emitCommonNeonBuiltinExpr(
23172317
// Determine the type of this overloaded NEON intrinsic.
23182318
NeonTypeFlags neonType(neonTypeConst->getZExtValue());
23192319
bool isUnsigned = neonType.isUnsigned();
2320+
bool isQuad = neonType.isQuad();
23202321
const bool hasLegalHalfType = getTarget().hasLegalHalfType();
23212322
// The value of allowBFloatArgsAndRet is true for AArch64, but it should
23222323
// come from ABI info.
@@ -2378,6 +2379,13 @@ mlir::Value CIRGenFunction::emitCommonNeonBuiltinExpr(
23782379
: "aarch64.neon.sqsub",
23792380
vTy, getLoc(e->getExprLoc()));
23802381
}
2382+
case NEON::BI__builtin_neon_vcvt_f32_v:
2383+
case NEON::BI__builtin_neon_vcvtq_f32_v: {
2384+
ops[0] = builder.createBitcast(ops[0], ty);
2385+
ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, isQuad),
2386+
hasLegalHalfType);
2387+
return builder.createCast(cir::CastKind::int_to_float, ops[0], ty);
2388+
}
23812389
case NEON::BI__builtin_neon_vext_v:
23822390
case NEON::BI__builtin_neon_vextq_v: {
23832391
int cv = getIntValueFromConstOp(ops[2]);

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,50 @@ uint32x2_t test_vqmovn_u64(uint64x2_t a) {
861861
// LLVM: [[VQMOVN_V1_I:%.*]] = call <2 x i32> @llvm.aarch64.neon.uqxtn.v2i32(<2 x i64> [[A]])
862862
// LLVM: ret <2 x i32> [[VQMOVN_V1_I]]
863863
}
864+
float32x2_t test_vcvt_f32_s32(int32x2_t a) {
865+
return vcvt_f32_s32(a);
866+
867+
// CIR-LABEL: vcvt_f32_s32
868+
// {{%.*}} = cir.cast(int_to_float, {{%.*}} : !cir.vector<!s32i x 2>), !cir.vector<!cir.float x 2>
869+
870+
// LLVM: {{.*}}test_vcvt_f32_s32(<2 x i32>{{.*}}[[a:%.*]])
871+
// LLVM: [[TMP0:%.*]] = bitcast <2 x i32> [[a]] to <8 x i8>
872+
// LLVM: [[VCVT_I:%.*]] = sitofp <2 x i32> [[a]] to <2 x float>
873+
// LLVM: ret <2 x float> [[VCVT_I]]
874+
}
875+
876+
float32x2_t test_vcvt_f32_u32(uint32x2_t a) {
877+
return vcvt_f32_u32(a);
878+
879+
// CIR-LABEL: vcvt_f32_u32
880+
// {{%.*}} = cir.cast(int_to_float, {{%.*}} : !cir.vector<!u32i x 2>), !cir.vector<!cir.float x 2>
881+
882+
// LLVM: {{.*}}test_vcvt_f32_u32(<2 x i32>{{.*}}[[a:%.*]])
883+
// LLVM: [[TMP0:%.*]] = bitcast <2 x i32> [[a]] to <8 x i8>
884+
// LLVM: [[VCVT_I:%.*]] = uitofp <2 x i32> [[a]] to <2 x float>
885+
// LLVM: ret <2 x float> [[VCVT_I]]
886+
}
887+
888+
float32x4_t test_vcvtq_f32_s32(int32x4_t a) {
889+
return vcvtq_f32_s32(a);
890+
891+
// CIR-LABEL: vcvtq_f32_s32
892+
// {{%.*}} = cir.cast(int_to_float, {{%.*}} : !cir.vector<!s32i x 4>), !cir.vector<!cir.float x 4>
893+
894+
// LLVM: {{.*}}test_vcvtq_f32_s32(<4 x i32>{{.*}}[[a:%.*]])
895+
// LLVM: [[TMP0:%.*]] = bitcast <4 x i32> [[a]] to <16 x i8>
896+
// LLVM: [[VCVT_I:%.*]] = sitofp <4 x i32> [[a]] to <4 x float>
897+
// LLVM: ret <4 x float> [[VCVT_I]]
898+
}
899+
900+
float32x4_t test_vcvtq_f32_u32(uint32x4_t a) {
901+
return vcvtq_f32_u32(a);
902+
903+
// CIR-LABEL: vcvtq_f32_u32
904+
// {{%.*}} = cir.cast(int_to_float, {{%.*}} : !cir.vector<!u32i x 4>), !cir.vector<!cir.float x 4>
905+
906+
// LLVM: {{.*}}test_vcvtq_f32_u32(<4 x i32>{{.*}}[[a:%.*]])
907+
// LLVM: [[TMP0:%.*]] = bitcast <4 x i32> [[a]] to <16 x i8>
908+
// LLVM: [[VCVT_I:%.*]] = uitofp <4 x i32> [[a]] to <4 x float>
909+
// LLVM: ret <4 x float> [[VCVT_I]]
910+
}

0 commit comments

Comments
 (0)