@@ -11339,6 +11339,37 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
11339
11339
11340
11340
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
11341
11341
}
11342
+ case Builtin::BI__builtin_elementwise_add_sat:
11343
+ case Builtin::BI__builtin_elementwise_sub_sat: {
11344
+ APValue SourceLHS, SourceRHS;
11345
+ if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
11346
+ !EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
11347
+ return false;
11348
+
11349
+ QualType DestEltTy = E->getType()->castAs<VectorType>()->getElementType();
11350
+ unsigned SourceLen = SourceLHS.getVectorLength();
11351
+ SmallVector<APValue, 4> ResultElements;
11352
+ ResultElements.reserve(SourceLen);
11353
+
11354
+ for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
11355
+ APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
11356
+ APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
11357
+ switch (E->getBuiltinCallee()) {
11358
+ case Builtin::BI__builtin_elementwise_add_sat:
11359
+ ResultElements.push_back(APValue(
11360
+ APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
11361
+ DestEltTy->isUnsignedIntegerOrEnumerationType())));
11362
+ break;
11363
+ case Builtin::BI__builtin_elementwise_sub_sat:
11364
+ ResultElements.push_back(APValue(
11365
+ APSInt(LHS.isSigned() ? LHS.ssub_sat(RHS) : RHS.usub_sat(RHS),
11366
+ DestEltTy->isUnsignedIntegerOrEnumerationType())));
11367
+ break;
11368
+ }
11369
+ }
11370
+
11371
+ return Success(APValue(ResultElements.data(), ResultElements.size()), E);
11372
+ }
11342
11373
}
11343
11374
}
11344
11375
@@ -13204,6 +13235,25 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
13204
13235
return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
13205
13236
}
13206
13237
13238
+ case Builtin::BI__builtin_elementwise_add_sat: {
13239
+ APSInt LHS, RHS;
13240
+ if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
13241
+ !EvaluateInteger(E->getArg(1), RHS, Info))
13242
+ return false;
13243
+
13244
+ APInt Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
13245
+ return Success(APSInt(Result, !LHS.isSigned()), E);
13246
+ }
13247
+ case Builtin::BI__builtin_elementwise_sub_sat: {
13248
+ APSInt LHS, RHS;
13249
+ if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
13250
+ !EvaluateInteger(E->getArg(1), RHS, Info))
13251
+ return false;
13252
+
13253
+ APInt Result = LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS);
13254
+ return Success(APSInt(Result, !LHS.isSigned()), E);
13255
+ }
13256
+
13207
13257
case Builtin::BIstrlen:
13208
13258
case Builtin::BIwcslen:
13209
13259
// A call to strlen is not a constant expression.
0 commit comments