Skip to content

Commit 95adde9

Browse files
committed
[CIR][CIRGen][AArch64] Make vrndns emit RoundEvenOp directly
1 parent 5a75305 commit 95adde9

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,6 +4787,7 @@ def Log2Op : UnaryFPToFPBuiltinOp<"log2", "Log2Op">;
47874787
def NearbyintOp : UnaryFPToFPBuiltinOp<"nearbyint", "NearbyintOp">;
47884788
def RintOp : UnaryFPToFPBuiltinOp<"rint", "RintOp">;
47894789
def RoundOp : UnaryFPToFPBuiltinOp<"round", "RoundOp">;
4790+
def RoundEvenOp : UnaryFPToFPBuiltinOp<"roundeven", "RoundEvenOp">;
47904791
def SinOp : UnaryFPToFPBuiltinOp<"sin", "SinOp">;
47914792
def SqrtOp : UnaryFPToFPBuiltinOp<"sqrt", "SqrtOp">;
47924793
def TruncOp : UnaryFPToFPBuiltinOp<"trunc", "FTruncOp">;

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ static mlir::Value vecReduceIntValue(CIRGenFunction &cgf, mlir::Value val,
22262226
loc, val, builder.getConstInt(loc, cgf.SizeTy, 0));
22272227
}
22282228

2229-
mlir::Value emitNeonCall(CIRGenBuilderTy &builder,
2229+
static mlir::Value emitNeonCall(CIRGenBuilderTy &builder,
22302230
llvm::SmallVector<mlir::Type> argTypes,
22312231
llvm::SmallVectorImpl<mlir::Value> &args,
22322232
llvm::StringRef intrinsicName, mlir::Type funcResTy,
@@ -2261,6 +2261,41 @@ mlir::Value emitNeonCall(CIRGenBuilderTy &builder,
22612261
.getResult();
22622262
}
22632263

2264+
template <typename Operation>
2265+
static mlir::Value emitNeonCall(CIRGenBuilderTy &builder,
2266+
llvm::SmallVector<mlir::Type> argTypes,
2267+
llvm::SmallVectorImpl<mlir::Value> &args,
2268+
mlir::Type funcResTy,
2269+
mlir::Location loc,
2270+
bool isConstrainedFPIntrinsic = false,
2271+
unsigned shift = 0, bool rightshift = false) {
2272+
// TODO: Consider removing the following unreachable when we have
2273+
// emitConstrainedFPCall feature implemented
2274+
assert(!cir::MissingFeatures::emitConstrainedFPCall());
2275+
if (isConstrainedFPIntrinsic)
2276+
llvm_unreachable("isConstrainedFPIntrinsic NYI");
2277+
2278+
for (unsigned j = 0; j < argTypes.size(); ++j) {
2279+
if (isConstrainedFPIntrinsic) {
2280+
assert(!cir::MissingFeatures::emitConstrainedFPCall());
2281+
}
2282+
if (shift > 0 && shift == j) {
2283+
args[j] = emitNeonShiftVector(builder, args[j],
2284+
mlir::cast<cir::VectorType>(argTypes[j]),
2285+
loc, rightshift);
2286+
} else {
2287+
args[j] = builder.createBitcast(args[j], argTypes[j]);
2288+
}
2289+
}
2290+
if (isConstrainedFPIntrinsic) {
2291+
assert(!cir::MissingFeatures::emitConstrainedFPCall());
2292+
return nullptr;
2293+
}
2294+
return builder
2295+
.create<Operation>(loc, funcResTy, args)
2296+
.getResult();
2297+
}
2298+
22642299
/// This function `emitCommonNeonCallPattern0` implements a common way
22652300
/// to generate neon intrinsic call that has following pattern:
22662301
/// 1. There is a need to cast result of the intrinsic call back to
@@ -4139,7 +4174,7 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
41394174
case NEON::BI__builtin_neon_vrndns_f32: {
41404175
mlir::Value arg0 = emitScalarExpr(E->getArg(0));
41414176
args.push_back(arg0);
4142-
return emitNeonCall(builder, {arg0.getType()}, args, "roundeven.f32",
4177+
return emitNeonCall<cir::RoundEvenOp>(builder, {arg0.getType()}, args,
41434178
getCIRGenModule().FloatTy, getLoc(E->getExprLoc()));
41444179
}
41454180
case NEON::BI__builtin_neon_vrndph_f16: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ float32_t test_vrndns_f32(float32_t a) {
2323
// CIR: cir.func internal private @vrndns_f32(%arg0: !cir.float {{.*}}) -> !cir.float
2424
// CIR: cir.store %arg0, [[ARG_SAVE:%.*]] : !cir.float, !cir.ptr<!cir.float>
2525
// CIR: [[INTRIN_ARG:%.*]] = cir.load [[ARG_SAVE]] : !cir.ptr<!cir.float>, !cir.float
26-
// CIR: {{%.*}} = cir.llvm.intrinsic "roundeven.f32" [[INTRIN_ARG]] : (!cir.float)
26+
// CIR: {{%.*}} = cir.roundeven [[INTRIN_ARG]] : !cir.float
2727
// CIR: cir.return {{%.*}} : !cir.float
2828

2929
// CIR-LABEL: test_vrndns_f32

0 commit comments

Comments
 (0)