@@ -2160,6 +2160,43 @@ static mlir::Value buildArmLdrexNon128Intrinsic(unsigned int builtinID,
2160
2160
}
2161
2161
}
2162
2162
2163
+ // / Given a vector of unsigned int type `vecTy`, return a vector type of
2164
+ // / signed int type with the same element type width and vector size.
2165
+ static mlir::cir::VectorType getSignedVectorType (CIRGenBuilderTy &builder,
2166
+ mlir::cir::VectorType vecTy) {
2167
+ auto elemTy = mlir::cast<mlir::cir::IntType>(vecTy.getEltType ());
2168
+ elemTy = builder.getSIntNTy (elemTy.getWidth ());
2169
+ return mlir::cir::VectorType::get (builder.getContext (), elemTy,
2170
+ vecTy.getSize ());
2171
+ }
2172
+
2173
+ // / Get integer from a mlir::Value that is an int constant or a constant op.
2174
+ static int64_t getIntValueFromConstOp (mlir::Value val) {
2175
+ auto constOp = mlir::cast<mlir::cir::ConstantOp>(val.getDefiningOp ());
2176
+ return (mlir::cast<mlir::cir::IntAttr>(constOp.getValue ()))
2177
+ .getValue ()
2178
+ .getSExtValue ();
2179
+ }
2180
+
2181
+ // / Build a constant shift amount vector of `vecTy` to shift a vector
2182
+ // / Here `shitfVal` is a constant integer that will be splated into a
2183
+ // / a const vector of `vecTy` which is the return of this function
2184
+ static mlir::Value buildNeonShiftVector (CIRGenBuilderTy &builder,
2185
+ mlir::Value shiftVal,
2186
+ mlir::cir::VectorType vecTy,
2187
+ mlir::Location loc, bool neg) {
2188
+ int shiftAmt = getIntValueFromConstOp (shiftVal);
2189
+ if (neg)
2190
+ shiftAmt = -shiftAmt;
2191
+ llvm::SmallVector<mlir::Attribute> vecAttr{
2192
+ vecTy.getSize (),
2193
+ // ConstVectorAttr requires cir::IntAttr
2194
+ mlir::cir::IntAttr::get (vecTy.getEltType (), shiftAmt)};
2195
+ mlir::cir::ConstVectorAttr constVecAttr = mlir::cir::ConstVectorAttr::get (
2196
+ vecTy, mlir::ArrayAttr::get (builder.getContext (), vecAttr));
2197
+ return builder.create <mlir::cir::ConstantOp>(loc, vecTy, constVecAttr);
2198
+ }
2199
+
2163
2200
mlir::Value buildNeonCall (CIRGenBuilderTy &builder,
2164
2201
llvm::SmallVector<mlir::Type> argTypes,
2165
2202
llvm::SmallVectorImpl<mlir::Value> &args,
@@ -2172,38 +2209,27 @@ mlir::Value buildNeonCall(CIRGenBuilderTy &builder,
2172
2209
assert (!MissingFeatures::buildConstrainedFPCall ());
2173
2210
if (isConstrainedFPIntrinsic)
2174
2211
llvm_unreachable (" isConstrainedFPIntrinsic NYI" );
2175
- // TODO: Remove the following unreachable and call it in the loop once
2176
- // there is an implementation of buildNeonShiftVector
2177
- if (shift > 0 )
2178
- llvm_unreachable (" Argument shift NYI" );
2179
2212
2180
2213
for (unsigned j = 0 ; j < argTypes.size (); ++j) {
2181
2214
if (isConstrainedFPIntrinsic) {
2182
2215
assert (!MissingFeatures::buildConstrainedFPCall ());
2183
2216
}
2184
2217
if (shift > 0 && shift == j) {
2185
- assert (!MissingFeatures::buildNeonShiftVector ());
2218
+ args[j] = buildNeonShiftVector (
2219
+ builder, args[j], mlir::cast<mlir::cir::VectorType>(argTypes[j]), loc,
2220
+ rightshift);
2186
2221
} else {
2187
2222
args[j] = builder.createBitcast (args[j], argTypes[j]);
2188
2223
}
2189
2224
}
2190
2225
if (isConstrainedFPIntrinsic) {
2191
2226
assert (!MissingFeatures::buildConstrainedFPCall ());
2192
2227
return nullptr ;
2193
- } else {
2194
- return builder
2195
- .create <mlir::cir::IntrinsicCallOp>(
2196
- loc, builder.getStringAttr (intrinsicName), funcResTy, args)
2197
- .getResult ();
2198
2228
}
2199
- }
2200
-
2201
- // / Get integer from a mlir::Value that is an int constant or a constant op.
2202
- static int64_t getIntValueFromConstOp (mlir::Value val) {
2203
- auto constOp = mlir::cast<mlir::cir::ConstantOp>(val.getDefiningOp ());
2204
- return (mlir::cast<mlir::cir::IntAttr>(constOp.getValue ()))
2205
- .getValue ()
2206
- .getSExtValue ();
2229
+ return builder
2230
+ .create <mlir::cir::IntrinsicCallOp>(
2231
+ loc, builder.getStringAttr (intrinsicName), funcResTy, args)
2232
+ .getResult ();
2207
2233
}
2208
2234
2209
2235
// / This function `buildCommonNeonCallPattern0` implements a common way
@@ -2231,23 +2257,6 @@ buildCommonNeonCallPattern0(CIRGenFunction &cgf, llvm::StringRef intrincsName,
2231
2257
return builder.createBitcast (res, resultType);
2232
2258
}
2233
2259
2234
- // / Build a constant shift amount vector of `vecTy` to shift a vector
2235
- // / Here `shitfVal` is a constant integer that will be splated into a
2236
- // / a const vector of `vecTy` which is the return of this function
2237
- static mlir::Value buildNeonShiftVector (CIRGenBuilderTy &builder,
2238
- mlir::Value shiftVal,
2239
- mlir::cir::VectorType vecTy,
2240
- mlir::Location loc, bool neg) {
2241
- int shiftAmt = getIntValueFromConstOp (shiftVal);
2242
- llvm::SmallVector<mlir::Attribute> vecAttr{
2243
- vecTy.getSize (),
2244
- // ConstVectorAttr requires cir::IntAttr
2245
- mlir::cir::IntAttr::get (vecTy.getEltType (), shiftAmt)};
2246
- mlir::cir::ConstVectorAttr constVecAttr = mlir::cir::ConstVectorAttr::get (
2247
- vecTy, mlir::ArrayAttr::get (builder.getContext (), vecAttr));
2248
- return builder.create <mlir::cir::ConstantOp>(loc, vecTy, constVecAttr);
2249
- }
2250
-
2251
2260
// / Build ShiftOp of vector type whose shift amount is a vector built
2252
2261
// / from a constant integer using `buildNeonShiftVector` function
2253
2262
static mlir::Value buildCommonNeonShift (CIRGenBuilderTy &builder,
@@ -2345,6 +2354,15 @@ mlir::Value CIRGenFunction::buildCommonNeonBuiltinExpr(
2345
2354
: " llvm.aarch64.neon.sqrdmulh.lane" ,
2346
2355
resTy, getLoc (e->getExprLoc ()));
2347
2356
}
2357
+ case NEON::BI__builtin_neon_vrshr_n_v:
2358
+ case NEON::BI__builtin_neon_vrshrq_n_v: {
2359
+ return buildNeonCall (
2360
+ builder, {vTy, isUnsigned ? getSignedVectorType (builder, vTy) : vTy},
2361
+ ops, isUnsigned ? " llvm.aarch64.neon.urshl" : " llvm.aarch64.neon.srshl" ,
2362
+ vTy, getLoc (e->getExprLoc ()), false , /* not fp constrained op*/
2363
+ 1 , /* second arg is shift amount */
2364
+ true /* rightshift */ );
2365
+ }
2348
2366
case NEON::BI__builtin_neon_vshl_n_v:
2349
2367
case NEON::BI__builtin_neon_vshlq_n_v: {
2350
2368
mlir::Location loc = getLoc (e->getExprLoc ());
0 commit comments