Skip to content

Commit 317985e

Browse files
authored
[CIR][CIRGen][Builtin][Neon] Lower neon_vbsl_v and neon_vbslq_v (#1206)
1 parent 65c857e commit 317985e

File tree

2 files changed

+404
-248
lines changed

2 files changed

+404
-248
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,19 @@ getHalfEltSizeTwiceNumElemsVecType(CIRGenBuilderTy &builder,
21802180
vecTy.getSize() * 2);
21812181
}
21822182

2183+
static cir::VectorType
2184+
castVecOfFPTypeToVecOfIntWithSameWidth(CIRGenBuilderTy &builder,
2185+
cir::VectorType vecTy) {
2186+
if (mlir::isa<cir::SingleType>(vecTy.getEltType()))
2187+
return cir::VectorType::get(builder.getContext(), builder.getSInt32Ty(),
2188+
vecTy.getSize());
2189+
if (mlir::isa<cir::DoubleType>(vecTy.getEltType()))
2190+
return cir::VectorType::get(builder.getContext(), builder.getSInt64Ty(),
2191+
vecTy.getSize());
2192+
llvm_unreachable(
2193+
"Unsupported element type in getVecOfIntTypeWithSameEltWidth");
2194+
}
2195+
21832196
/// Get integer from a mlir::Value that is an int constant or a constant op.
21842197
static int64_t getIntValueFromConstOp(mlir::Value val) {
21852198
auto constOp = mlir::cast<cir::ConstantOp>(val.getDefiningOp());
@@ -3832,7 +3845,17 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
38323845
return nullptr;
38333846
case NEON::BI__builtin_neon_vbsl_v:
38343847
case NEON::BI__builtin_neon_vbslq_v: {
3835-
llvm_unreachable("NEON::BI__builtin_neon_vbslq_v NYI");
3848+
cir::VectorType bitTy = vTy;
3849+
if (cir::isAnyFloatingPointType(bitTy.getEltType()))
3850+
bitTy = castVecOfFPTypeToVecOfIntWithSameWidth(builder, vTy);
3851+
Ops[0] = builder.createBitcast(Ops[0], bitTy);
3852+
Ops[1] = builder.createBitcast(Ops[1], bitTy);
3853+
Ops[2] = builder.createBitcast(Ops[2], bitTy);
3854+
3855+
Ops[1] = builder.createAnd(Ops[0], Ops[1]);
3856+
Ops[2] = builder.createAnd(builder.createNot(Ops[0]), Ops[2]);
3857+
Ops[0] = builder.createOr(Ops[1], Ops[2]);
3858+
return builder.createBitcast(Ops[0], ty);
38363859
}
38373860
case NEON::BI__builtin_neon_vfma_lane_v:
38383861
case NEON::BI__builtin_neon_vfmaq_lane_v: { // Only used for FP types

0 commit comments

Comments
 (0)