222 Commits

Author SHA1 Message Date
Marco Elver
150053627d
[AllocToken] Fix and clarify -falloc-token-max=0 (#168689)
The option -falloc-token-max=0 is supposed to be usable to override
previous settings back to the target default max tokens (SIZE_MAX).

This did not work for the builtin:
```
| executed command: clang -cc1 [..] -nostdsysteminc -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify clang/test/SemaCXX/alloc-token.cpp -falloc-token-max=0
| clang: llvm/lib/Support/AllocToken.cpp:38: std::optional<uint64_t> llvm::getAllocToken(AllocTokenMode, const AllocTokenMetadata &, uint64_t): Assertion `MaxTokens && "Must provide non-zero max tokens"' failed.
```

Fix it by also picking the default if "0" is passed.

Improve the documentation to be clearer what the value of "0" means.
2025-11-19 12:15:15 +01:00
woruyu
f9256ca6cc
[Headers][X86] Allow AVX512 masked arithmetic ss/sd intrinsics to be used in constexpr (#162816)
This PR just resolves ss/sd part of AVX512 masked arithmetic intrinsics of #160559.
2025-11-18 10:23:39 +00:00
Ahmed Nour
47c1aa4cef
[X86] Add constexpr support for addsub intrinsics (#167512)
Recent commits (7fe069121b57a, 53ddeb493529a) marked several x86
intrinsics as constexpr in headers without providing the necessary
constant evaluation support in the compiler backend. This caused
compilation failures when attempting to use these intrinsics in constant
expressions.

Resolves #166814 
Resolves #161203
2025-11-17 15:34:34 +00:00
Ahmed Nour
44f72fb39c
[X86][Clang] Add AVX512 kunpck intrinsics to be used in constexp (#167683)
Resolves #166976
2025-11-17 10:06:50 +00:00
Timm Baeder
90e1391d18
[clang][bytecode] Check pointers in GetPtrField{,Pop} (#167335)
The pointer needs to point to a record.

Fixes https://github.com/llvm/llvm-project/issues/166371
2025-11-17 08:24:44 +01:00
clf
f210fc1a1c
[Clang] Add __builtin_bswapg (#162433)
Add a new builtin function __builtin_bswapg. It works on any integral
types that has a multiple of 16 bits as well as a single byte.

Closes #160266
2025-11-15 12:27:38 -08:00
NagaChaitanya Vellanki
91a1bde7b8
[Clang] Add constexpr support for AVX512 permutexvar intrinsics (#167802)
Resolves #167476
2025-11-13 14:07:58 +00:00
TelGome
ddaa2c307d
[Clang] Generalize interp__builtin_ia32_shuffle_generic to handle single op permute shuffles. (#167236)
This patch extends `interp__builtin_ia32_shuffle_generic` and `evalShuffleGeneric` to handle both 2-argument and 3-argument patterns, replacing specialized shuffle functions with the unified handler.

Resolves #166342
2025-11-11 14:51:10 +00:00
Ye Tian
f2a4287d49
[Headers][X86] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow PALIGNR byte shift intrinsics to be used in constexpr (#162005)
Fixes #160509
2025-11-11 12:41:03 +00:00
Roberto Turrado Camblor
c2fe1d94ee
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add AVX512 KTEST/KORTEST intrinsics to be used in constexpr (#166103)
Add AVX512 KTEST/KORTEST intrinsics to be used in constexpr.

Fixes #162051
2025-11-07 11:26:47 +00:00
NagaChaitanya Vellanki
cc9ad9afc6
[Clang] Add constexpr support for AVX512 permutex2 intrinsics (#165085)
This patch enables compile-time evaluation of AVX512 permutex2var
intrinsics in constexpr contexts.

Extend shuffle generic to handle both integer immediate and vector mask
operands.

Resolves #161335
2025-11-05 09:58:30 +00:00
Ahmed Nour
cf85cf4523
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow insertps intrinsic to be used in constexp (#165513)
Resolves #165161
2025-10-30 19:07:00 +00:00
Timm Baeder
a21521a4ef
[clang][bytecode] Check builtin carryops for non-block out pointers (#165512)
Fixes https://github.com/llvm/llvm-project/issues/165372
2025-10-29 07:30:11 +01:00
sskzakaria
0b1ef8c6b2
[X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation (#164026)
Enables constexpr evaluation for the following AVX512 Integer Comparison Intrinsics:
```
_mm_cmp_epi8_mask _mm_cmp_epu8_mask
_mm_cmp_epi16_mask _mm_cmp_epu16_mask
_mm_cmp_epi32_mask _mm_cmp_epu32_mask
_mm_cmp_epi64_mask _mm_cmp_epu64_mask

_mm256_cmp_epi8_mask _mm256_cmp_epu8_mask
_mm256_cmp_epi16_mask _mm256_cmp_epu16_mask
_mm256_cmp_epi32_mask _mm256_cmp_epu32_mask
_mm256_cmp_epi64_mask _mm256_cmp_epu64_mask

_mm512_cmp_epi8_mask _mm512_cmp_epu8_mask
_mm512_cmp_epi16_mask _mm512_cmp_epu16_mask
_mm512_cmp_epi32_mask _mm512_cmp_epu32_mask
_mm512_cmp_epi64_mask _mm512_cmp_epu64_mask
```
Part 1 of #162054
2025-10-28 16:05:20 +00:00
Timm Baeder
e624048f5c
[clang][bytecode] Check overflow ops for block pointers (#165221)
We can't save the result in a non-block pointer.

Fixes https://github.com/llvm/llvm-project/issues/165076
2025-10-27 11:55:52 +01:00
Timm Baeder
5d1e1cfa08
[clang][bytecode] Check memcmp for block pointers (#165070)
We can't read from non-block pointers anyway.

Fixes https://github.com/llvm/llvm-project/issues/165061
2025-10-27 10:43:01 +01:00
NagaChaitanya Vellanki
2db482d4ea
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow shufps/pd shuffles intrinsics to be used in constexpr (#164078)
Resolves #161208
2025-10-24 11:09:38 +00:00
Ye Tian
27453ce521
[Headers][X86] Allow SLLDQ/SRLDQ byte shift intrinsics to be used in constexpr (#164166)
Support constexpr usage for SLLDQ/SRLDQ byte shift intrinsics

This draft PR adds support for using the following SRLDQ intrinsics in
constant expressions:
- _mm_srli_si128
- _mm256_srli_si256
- _mm_slli_si128
- _mm256_slli_si256

Relevant tests are included.

Fixes #156494
2025-10-24 08:28:12 +00:00
Marco Elver
7ca1472df0
[Clang] Implement constexpr evaluation for __builtin_infer_alloc_token() (#163639)
Implement the constexpr evaluation for `__builtin_infer_alloc_token()`
in Clang's constant expression evaluators (both in ExprConstant and the
new bytecode interpreter).

The constant evaluation is only supported for stateless (hash-based)
token modes. If a stateful mode like `increment` is used, the evaluation
fails, as the token value is not deterministic at compile time.
2025-10-23 18:14:33 +02:00
Shawn K
1c33b82071
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow MMX/SSE/AVX2 PSIGN intrinsics to be used in constexpr (#163685)
Fix #155812
2025-10-23 14:18:49 +00:00
don
d2889d7ce3
[clang][x86][bytecode] remove trailing returns type from interp__builtin_elementwise_int_binop callbacks (#164679)
Related to the discussion in #162346, this PR is to remove the trailing type from the 'interp__builtin_elementwise_int_binop' callbacks.
2025-10-23 08:43:22 +00:00
Timm Baeder
1e99026b45
[clang][bytecode] Fix __builtin_strchr with unsigned chars (#164410)
Get the zero-extended truncated desired value in that case. Add one RUN
line to the constexpr-string.cpp test case, to not increase the runtime
of that test too much.
2025-10-21 16:32:19 +02:00
Timm Baeder
c8c5a382a2
[clang][bytecode] Move shared interp functions to InterpHelpers.h (#164215)
This drastically reduces the preprocessed size of Context.cpp and
InterpBuiltin.cpp.
2025-10-21 14:25:59 +02:00
SeongJaePark
e10afe01ec
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow AVX/AVX512 subvector extraction intrinsics to be used in constexpr #157712 (#162836)
**This PR supersedes and replaces PR #158853**

The original branch diverged too far from the main branch, resulting in
significant merge conflicts that were difficult to resolve cleanly. To
provide a clean and reviewable history, this new PR was created by
cherry-picking the necessary commits onto a fresh branch based on the
latest `main`.

---

*(Original Description)*

This patch enables the use of AVX/AVX512 subvector extraction intrinsics
within `constexpr` functions. This is achieved by implementing the
evaluation logic for these intrinsics in
`VectorExprEvaluator::VisitCallExpr` and `InterpretBuiltin`.

The original discussion and review comments can be found in the previous
pull request for context: #158853

Fixes #157712
2025-10-20 17:42:10 +00:00
Shawn K
725a297176
[Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (#161914)
Fix #154520
2025-10-20 17:09:46 +00:00
Shawn K
3afbda091a
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow SSE41 phminposuw intrinsic to be used in constexp (#163041)
Fix #161336
2025-10-20 17:00:16 +00:00
Temperz87
ee530f0fb1
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add MMX/SSE/AVX/AVX512 PMULHRSW intrinsics to be used in constexpr (#160636)
This PR resolves #155805 and updates the following builtins to handle
constant expressions:

```
_mm_mulhrs_pi16
mm_mulhrs_epi16 mm256_mulhrs_epi16 mm512_mulhrs_epi16
```
2025-10-18 20:10:50 +00:00
don
df2ff3a1b2
[clang][x86][bytecode] remove trailing returns type from interp__builtin_elementwise_int_unaryop callbacks (#163905)
Regarding the discussion in #162346, this PR is to remove the trailing type from the 'interp__builtin_elementwise_int_unaryop' callbacks.
2025-10-17 17:43:18 +01:00
Kazu Hirata
1dfbfbd637
[clang] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163914)
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]],
introduced as part of C++17.
2025-10-17 07:27:11 -07:00
NagaChaitanya Vellanki
d2a8486069
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX512 conflict intrinsics to be used in constexpr (#163293)
Resolves #160524
2025-10-16 10:01:35 +00:00
shashank1545
140d46579f
[X86][ByteCode] Allow PSHUFB intrinsics to be used in constexpr #156612 (#163148)
The PSHUFB instruction shuffles bytes within each 128-bit lane: for each
control byte, if bit 7 is set, the output byte is zeroed; otherwise, the
low 4 bits select a source byte (0–15) from the same lane.

Note: _mm_shuffle_pi8 function had to change as __anyext128 had negative
indices which are invalid in constant expression context.

Fixes #156612
2025-10-15 09:27:49 +00:00
NagaChaitanya Vellanki
b110b7d30a
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX/AVX512 IFMA madd52 intrinsics to be used in constexpr (#161056)
Resolves #160498
2025-10-14 13:35:03 +00:00
why
53ddeb4935
[X86] Add MMX/SSE/AVX PHADD/SUB & HADDPS/D intrinsics to be used in constexpr (#156822)
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add MMX/SSE/AVX PHADD/SUB & HADDPS/D intrinsics to be used in constexpr

Fixes #155395

cover func: 
_mm_hadd_pi16 _mm_hadd_epi16 _mm256_hadd_epi16 
_mm_hadd_pi32 _mm_hadd_epi32 _mm256_hadd_epi32
_mm_hadds_pi16 _mm_hadds_epi16 _mm256_hadds_epi16 

_mm_hsub_pi16 _mm_hsub_epi16 _mm256_hsub_epi16 
_mm_hsub_pi32 _mm_hsub_epi32 _mm256_hsub_epi32
_mm_hsubs_pi16 _mm_hsubs_epi16 _mm256_hsubs_epi16 

_mm_hadd_pd _mm256_hadd_pd
_mm_hadd_ps _mm256_hadd_ps
_mm_hsub_pd _mm256_hsub_pd
_mm_hsub_ps _mm256_hsub_ps

---------

Co-authored-by: whyuuwang <whyuuwang@tencent.com>
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
Co-authored-by: Simon Pilgrim <git@redking.me.uk>
2025-10-14 10:54:10 +00:00
Shawn K
e3f22d9ee4
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add SSE/AVX VPTEST/VTESTPD/VTESTPS intrinsics to be used in constexpr (#160428)
Fix #158653

Add handling for:
```
ptestz128 / ptestz256 → (a & b) == 0.
ptestc128 / ptestc256 → (~a & b) == 0
ptestnzc128 / ptestnzc256 → (a & b) != 0  AND  (~a & b) != 0.
vtestzps / vtestzps256 → (S(a) & S(b)) == 0.
vtestcps / vtestcps256 → (~S(a) & S(b)) == 0.
vtestnzcps / vtestnzcps256 → (S(a) & S(b)) != 0  AND  (~S(a) & S(b)) != 0.
vtestzpd / vtestzpd256 → (S(a) & S(b)) == 0.
vtestcpd / vtestcpd256 → (~S(a) & S(b)) == 0.
vtestnzcpd / vtestnzcpd256 → (S(a) & S(b)) != 0  AND  (~S(a) & S(b)) != 0.
```
Add corresponding test cases for:
```
int _mm_test_all_ones (__m128i a)
int _mm_test_all_zeros (__m128i mask, __m128i a)
int _mm_test_mix_ones_zeros (__m128i mask, __m128i a)
int _mm_testc_pd (__m128d a, __m128d b)
int _mm256_testc_pd (__m256d a, __m256d b)
int _mm_testc_ps (__m128 a, __m128 b)
int _mm256_testc_ps (__m256 a, __m256 b)
int _mm_testc_si128 (__m128i a, __m128i b)
int _mm256_testc_si256 (__m256i a, __m256i b)
int _mm_testnzc_pd (__m128d a, __m128d b)
int _mm256_testnzc_pd (__m256d a, __m256d b)
int _mm_testnzc_ps (__m128 a, __m128 b)
int _mm256_testnzc_ps (__m256 a, __m256 b)
int _mm_testnzc_si128 (__m128i a, __m128i b)
int _mm256_testnzc_si256 (__m256i a, __m256i b)
int _mm_testz_pd (__m128d a, __m128d b)
int _mm256_testz_pd (__m256d a, __m256d b)
int _mm_testz_ps (__m128 a, __m128 b)
int _mm256_testz_ps (__m256 a, __m256 b)
int _mm_testz_si128 (__m128i a, __m128i b)
int _mm256_testz_si256 (__m256i a, __m256i b)
```
2025-10-13 10:01:35 +00:00
Timm Baeder
322c1a25c3
[clang][bytecode] Fix a few coding style mishaps (#163045)
PrimType variables end in T, not PT. Remove const from local primitive
variables.
2025-10-12 09:41:20 +02:00
Simon Pilgrim
7f8d9b0bf9
[clang][bytecode][x86] Merge interp__builtin_ia32_pmul/interp__builtin_ia32_pmadd implementations (#162504)
The interp__builtin_ia32_pmadd implementation can be correctly used for
PMULDQ/PMULUDQ evaluation as well as we're ignoring the "hi" integers in
each pair

I've replaced the PMULDQ/PMULUDQ evaluation with callbacks and renamed
interp__builtin_ia32_pmadd to interp__builtin_ia32_pmul for consistency
2025-10-09 07:59:46 +01:00
Bhasawut Singhaphan
ee192315b2
[Headers][X86] Enable constexpr handling for MMX/SSE/AVX/AVX512 PMADDWD/PMADDUBSW intrinsics (#161563)
This PR updates the PMADDWD/PMADDUBSW builtins to support constant
expression handling, by extending the VectorExprEvaluator::VisitCallExpr
that handles interp__builtin_ia32_pmadd builtins.

Closes #155392
2025-10-08 14:30:14 +00:00
don
d0da85745d
[clang][x86][bytecode] Replace interp__builtin_parity/clrsb/bitreverse/ffs with static bool interp__builtin_elementwise_int_unaryop callback (#162346)
Fixes #160288
2025-10-08 14:15:23 +00:00
Timm Baeder
bb09cc41cf
[clang][bytecode] Fix a crash in __builtin_object_size() (#160519)
The previous `ByteOffset` computation only makes sense if `Ptr` points
into an array.
2025-10-07 08:21:21 +02:00
Shawn K
d7feeda437
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - add AVX512 VPTERNLOGD/VPTERNLOGQ intrinsics to be used in constexpr (#158703)
Fix #157698 

Add handling for `__builtin_ia32_pternlog[d/q][128/256/512]_mask[z]` intrinsics to `VectorExprEvaluator::VisitCallExpr` and `InterpBuiltin.cpp` with the corresponding test coverage:

```
_mm_mask_ternarylogic_epi32
_mm_maskz_ternarylogic_epi32
_mm_ternarylogic_epi32
_mm256_mask_ternarylogic_epi32
_mm256_maskz_ternarylogic_epi32
_mm256_ternarylogic_epi32
_mm512_mask_ternarylogic_epi32
_mm512_maskz_ternarylogic_epi32
_mm512_ternarylogic_epi32
_mm_mask_ternarylogic_epi64
_mm_maskz_ternarylogic_epi64
_mm_ternarylogic_epi64
_mm256_mask_ternarylogic_epi64
_mm256_maskz_ternarylogic_epi64
_mm256_ternarylogic_epi64
_mm512_mask_ternarylogic_epi64
_mm512_maskz_ternarylogic_epi64
_mm512_ternarylogic_epi64
```

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-10-06 16:44:37 +00:00
rdez13
e573c795e4
[clang][x86][bytecode] Replace interp__builtin_rotate with static bool interp__builtin_elementwise_int_binop callback #160289 (#161924)
Fixes #160289
2025-10-06 07:58:40 +00:00
Simon Pilgrim
1af06cb636
[clang][bytecode] interp__builtin_ia32_pshuf - modulo lane index to allow reuse of PSHUFD/LW/HW mask decode. NFC (#162006)
Removes need to offset PSHUFHW land index to extract the shuffle mask element.
2025-10-05 11:37:16 +00:00
Nagraj Gaonkar
952b12394e
[X86] Allow PSHUFD/PSHUFLW/PSHUFW intrinsics in constexpr. (#161210)
The i16/i32 shuffle intrinsics (`pshufw`, `pshuflw`, `pshufhw`,
`pshufd`) currently cannot be used in constant expressions. This patch
adds support in both bytecode interpreter (InterpBuiltin.cpp) and
constant evaluator
(ExprConstant.cpp) for pshuf intrinsics, enabling their use in constant
expressions.
## Intrinsics covered
- `_mm_shuffle_pi16` (MMX `pshufw`)
- `_mm_shufflelo_epi16` / `_mm_shufflehi_epi16`
- `_mm_shuffle_epi32`
- Their AVX2/AVX512 vector-width variants
- Masked and maskz forms (handled indirectly via
`__builtin_ia32_select*`)

Fixes #156611
2025-10-03 15:52:21 +01:00
Aditya Chaudhari
9e3bbbb049
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow element extraction/insertion intrinsics to be used in constexpr #159753 (#161302)
FIXES: #159753

Enable constexpr evaluation for X86 vector element extract/insert builtins. and adds corresponding tests
Index is masked with `(Idx & (NumElts - 1))`, matching existing CodeGen.
2025-10-03 13:08:39 +00:00
jiang1997
0251fd9a72
[clang][x86][bytecode] Refactor BMI intrinsic wrappers to use interp__builtin_elementwise_int_binop (#160362)
Fixes #160281
2025-09-29 17:27:16 +00:00
Timm Baeder
538cd20cfa
[clang][bytecode][NFC] Simplify a few builtin implementations (#160910) 2025-09-27 07:47:02 +02:00
Timm Baeder
88324f1cab
[clang][bytecode][NFC] Simplify align_up/down implementation (#160880)
Fix a double assignment to a local variable and use the new
popToAPSInt() overload.
2025-09-26 17:26:38 +02:00
Kazu Hirata
92e5060e4c [AST] Fix a warning
This patch fixes:

  clang/lib/AST/ByteCode/InterpBuiltin.cpp:2603:15: error: unused
  variable 'VT1' [-Werror,-Wunused-variable]
2025-09-24 08:06:47 -07:00
woruyu
0a268f803c
[Headers][X86] VectorExprEvaluator::VisitCallExpr - allow SSE/AVX2/AVX512 pack intrinsics to be used in constexpr (#156003)
Fixes #154283
2025-09-24 13:03:29 +00:00
fennecJ
d5f85782e8
[clang][x86][bytecode] Replace interp__builtin_knot with static bool interp__builtin_elementwise_int_unaryop callback (#160332)
Fix #160287
2025-09-23 16:45:35 +00:00