[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

Pol M via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 31 07:38:19 PDT 2024


Pol Marcet =?utf-8?q?Sardà?= <polmarcetsarda at gmail.com>,
Pol Marcet =?utf-8?q?Sardà?= <polmarcetsarda at gmail.com>,Pol M
 <polmarcetsarda at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/76615 at github.com>


================
@@ -10895,6 +10899,132 @@ bool VectorExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
   return Success(APValue(ResultElements.data(), ResultElements.size()), E);
 }
 
+static bool EvaluateVectorOrLValue(APValue &Result, EvalInfo &Info,
+                                   const Expr *E, const QualType &Type) {
+  if (!Evaluate(Result, Info, E))
+    return false;
+
+  if (Result.isLValue()) {
+    // Source of the data is an lvalue; Manually handle the lvalue as if
+    // it was an rvalue to get the current APValue.
+    LValue LValueFound;
+    LValueFound.setFrom(Info.Ctx, Result);
+    if (!handleLValueToRValueConversion(Info, E, Type, LValueFound, Result))
+      return false;
+  }
+
+  return Result.isVector();
+}
+
+static bool handleVectorConversion(EvalInfo &Info, const FPOptions FPO,
+                                   const Expr *E, QualType SourceTy,
+                                   QualType DestTy, APValue const &Original,
+                                   APValue &Result) {
+  if (SourceTy->isIntegerType()) {
+    if (DestTy->isRealFloatingType()) {
+      Result = APValue(APFloat(0.0));
+      return HandleIntToFloatCast(Info, E, FPO, SourceTy, Original.getInt(),
+                                  DestTy, Result.getFloat());
----------------
Destroyerrrocket wrote:

I think that beyond some differences in memory layout, I'd expect the performance to be about the same for the normal case. The bad case might be able to save a bit of performance by avoiding a copy (happening inside the APValue) (that probably will get optimized anyway). Without measuring, I think this is performant enough, and I value code being short and easy enough to read (not that the proposed code is bad in any way; If I saw it in a PR I wouldn't even blink)

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


More information about the cfe-commits mailing list