Skip to content

Commit 596b9e9

Browse files
AmrDeveloperlanza
authored andcommitted
[CIR][CIRGen][Builtin][Neon] Lower neon_vset_lane_f64 (#1253)
Lowering Neon `vset_lane_f64` References: [Clang CGBuiltin Implementation](https://github.com/llvm/clangir/blob/2b1a638ea07ca10c5727ea835bfbe17b881175cc/clang/lib/CodeGen/CGBuiltin.cpp#L12342) [Builtin definition](https://developer.arm.com/architectures/instruction-sets/intrinsics/vset_lane_f64)
1 parent 541f20a commit 596b9e9

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,17 +3688,21 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
36883688
// at the moment, the implementation should be the same as above
36893689
// vset_lane or vsetq_lane intrinsics
36903690
llvm_unreachable("NEON::BI__builtin_neon_vsetq_lane_bf16 NYI");
3691-
case NEON::BI__builtin_neon_vset_lane_f64:
3692-
// The vector type needs a cast for the v1f64 variant.
3693-
llvm_unreachable("NEON::BI__builtin_neon_vset_lane_f64 NYI");
3691+
3692+
case NEON::BI__builtin_neon_vset_lane_f64: {
3693+
Ops.push_back(emitScalarExpr(E->getArg(2)));
3694+
Ops[1] = builder.createBitcast(
3695+
Ops[1], cir::VectorType::get(&getMLIRContext(), DoubleTy, 1));
3696+
return builder.create<cir::VecInsertOp>(getLoc(E->getExprLoc()), Ops[1],
3697+
Ops[0], Ops[2]);
3698+
}
36943699
case NEON::BI__builtin_neon_vsetq_lane_f64: {
36953700
Ops.push_back(emitScalarExpr(E->getArg(2)));
36963701
Ops[1] = builder.createBitcast(
36973702
Ops[1], cir::VectorType::get(&getMLIRContext(), DoubleTy, 2));
36983703
return builder.create<cir::VecInsertOp>(getLoc(E->getExprLoc()), Ops[1],
36993704
Ops[0], Ops[2]);
37003705
}
3701-
37023706
case NEON::BI__builtin_neon_vget_lane_i8:
37033707
case NEON::BI__builtin_neon_vdupb_lane_i8:
37043708
Ops[0] = builder.createBitcast(

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,27 @@ float32x4_t test_vsetq_lane_f32(float32_t a, float32x4_t b) {
137137
// LLVM: [[INTRN_RES:%.*]] = insertelement <4 x float> [[B]], float [[A]], i32 3
138138
// LLVM: ret <4 x float> [[INTRN_RES]]
139139

140-
float64x2_t test_vsetq_land_f64(float64_t a, float64x2_t b) {
140+
float64x1_t test_vset_lane_f64(float64_t a, float64x1_t b) {
141+
return vset_lane_f64(a, b, 0);
142+
}
143+
144+
// CIR-LABEL: test_vset_lane_f64
145+
// CIR: [[IDX:%.*]] = cir.const #cir.int<0> : !s32i
146+
// CIR: {{%.*}} = cir.vec.insert {{%.*}}, {{%.*}}[[[IDX]] : !s32i] : !cir.vector<!cir.double x 1>
147+
148+
// LLVM: {{.*}}test_vset_lane_f64(double{{.*}}[[A:%.*]], <1 x double>{{.*}}[[B:%.*]])
149+
// LLVM: [[INTRN_RES:%.*]] = insertelement <1 x double> [[B]], double [[A]], i32 0
150+
// LLVM: ret <1 x double> [[INTRN_RES]]
151+
152+
float64x2_t test_vsetq_lane_f64(float64_t a, float64x2_t b) {
141153
return vsetq_lane_f64(a, b, 0);
142154
}
143155

144-
// CIR-LABEL: test_vsetq_land_f64
156+
// CIR-LABEL: test_vsetq_lane_f64
145157
// CIR: [[IDX:%.*]] = cir.const #cir.int<0> : !s32i
146158
// CIR: {{%.*}} = cir.vec.insert {{%.*}}, {{%.*}}[[[IDX]] : !s32i] : !cir.vector<!cir.double x 2>
147159

148-
// LLVM: {{.*}}test_vsetq_land_f64(double{{.*}}[[A:%.*]], <2 x double>{{.*}}[[B:%.*]])
160+
// LLVM: {{.*}}test_vsetq_lane_f64(double{{.*}}[[A:%.*]], <2 x double>{{.*}}[[B:%.*]])
149161
// LLVM: [[INTRN_RES:%.*]] = insertelement <2 x double> [[B]], double [[A]], i32 0
150162
// LLVM: ret <2 x double> [[INTRN_RES]]
151163

0 commit comments

Comments
 (0)