Skip to content

let Neon builtin function accept a const variable #144625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

scout-zeng
Copy link

FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count) { long long c = count.vect_s64[0]; const int mc = c; __m128i result_m128i; if (likely(c >= 0 && c < 64)) { result_m128i.vect_s64 = vshlq_n_s64(a.vect_s64, mc); } else { result_m128i.vect_s64 = vdupq_n_s64(0); } return result_m128i; }
vshlq_n_s64 is an Neon intrinsics, 2nd parameter of this function needs a const int, however it failed in current CLANG Latest version. This patch used to support this feature which make Neon intrinsics can receive a const int variable instead of literal.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2025

@llvm/pr-subscribers-clang

Author: None (scout-zeng)

Changes

FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count) { long long c = count.vect_s64[0]; const int mc = c; __m128i result_m128i; if (likely(c &gt;= 0 &amp;&amp; c &lt; 64)) { result_m128i.vect_s64 = vshlq_n_s64(a.vect_s64, mc); } else { result_m128i.vect_s64 = vdupq_n_s64(0); } return result_m128i; }
vshlq_n_s64 is an Neon intrinsics, 2nd parameter of this function needs a const int, however it failed in current CLANG Latest version. This patch used to support this feature which make Neon intrinsics can receive a const int variable instead of literal.


Full diff: https://github.com/llvm/llvm-project/pull/144625.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaChecking.cpp (+4-3)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 69276ce418fa6..f9fc0ff536254 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5666,11 +5666,12 @@ bool Sema::BuiltinConstantArg(CallExpr *TheCall, int ArgNum,
 
   if (Arg->isTypeDependent() || Arg->isValueDependent()) return false;
 
-  std::optional<llvm::APSInt> R;
-  if (!(R = Arg->getIntegerConstantExpr(Context)))
+  Expr::EvalResult evalRes;
+  if (!Arg->EvaluateAsInt(evalRes, Context)) {
     return Diag(TheCall->getBeginLoc(), diag::err_constant_integer_arg_type)
            << FDecl->getDeclName() << Arg->getSourceRange();
-  Result = *R;
+  }
+  Result = evalRes.Val.getInt();
   return false;
 }
 

@scout-zeng
Copy link
Author

@efriedma-quic Hi Eli, if there is any problem, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants