[clang] [clang] constexpr built-in reduce add function. (PR #116243)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 18 04:17:06 PST 2024


================
@@ -13528,6 +13528,24 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     return Success(DidOverflow, E);
   }
 
+  case Builtin::BI__builtin_reduce_add: {
+    APValue Source;
+    if (!EvaluateAsRValue(Info, E->getArg(0), Source))
+      return false;
+
+    unsigned SourceLen = Source.getVectorLength();
+    APSInt Reduced = Source.getVectorElt(0).getInt();
+    for (unsigned EltNum = 1; EltNum < SourceLen; ++EltNum) {
+      if (!CheckedIntArithmetic(
+              Info, E, Reduced, Source.getVectorElt(EltNum).getInt(),
+              Reduced.getBitWidth() + 1, std::plus<APSInt>(), Reduced)) {
+        return false;
+      }
----------------
c8ef wrote:

Aha, you are right! This will align the patch more with llvm code style.

https://github.com/llvm/llvm-project/pull/116243


More information about the cfe-commits mailing list