258 Commits

Author SHA1 Message Date
Julian Pokrovsky
d836261ca3
[X86][Clang] allow CRC32 intrinsics to be used in constexp (#173908)
Mostly inspired by https://github.com/llvm/llvm-project/pull/152971

CRC32 implementation using reversed polynomial that does not match an
Intel manual, can be changed to canonical implementation if required (if
there is a canonical implementation we should use, please attach a link)

Closes #168881 
Part of #30794
2026-01-21 16:34:30 +00:00
NagaChaitanya Vellanki
370529c7f7
[clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (#160259)
This patch adds type-generic rotate builtins that accept any unsigned
integer
type. These builtins provide:

- Support for all unsigned integer types, including _BitInt
- Constexpr evaluation capability
- Automatic normalization of rotation counts modulo the bit-width
- Proper handling of negative rotation counts (converted to equivalent
  positive rotations in the opposite direction)
- Implicit conversion support for both arguments for
  types with conversion operators. 

The builtins follow C23 naming conventions.

Resolves https://github.com/llvm/llvm-project/issues/122819
2026-01-21 10:30:45 +01:00
Timm Baeder
a15adf5b9b
[clang][bytecode][NFC] Add Pointer::stripBaseCasts() helper (#176875)
We do this is in a few places, so add a helper function for it.
2026-01-20 11:21:22 +01:00
Timm Baeder
222fff827e
[clang][bytecode] Remove base casts in builtin_object_size (#176111)
If UseFieldDesc is set, we should use the "closest surrounding
subobject", which apparently cannot be a subclass pointer.

Fixes https://github.com/llvm/llvm-project/issues/176079
2026-01-15 11:44:56 +01:00
Simon Pilgrim
8784816a41
[ADT] Add APInt::truncSSatU truncation from signed to unsigned variant (#175603)
This matches the behaviour of ISD::TRUNCATE_SSAT_U and X86ISD::PACKUS
truncations: saturate signed input to unsigned result -
`truncate(smin(smax(x, 0), C))`

Add unit test coverage and update existing PACKUS constant folding to
use the APInt helper
2026-01-13 17:51:07 +00:00
Timm Baeder
25b4d1e1de
[clang][bytecode] Don't evaluate builtin_assume argument (#175740)
This is what the current interpreter does.
2026-01-13 12:33:58 +01:00
NagaChaitanya Vellanki
52d6170c9f
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow SSE/AVX FP MAX/MIN intrinsics to be used in constexpr (#171966)
* Implemented a generic function interp__builtin_elementwise_fp_binop
* NaN, Infinity, Denormal cases can be integrated into the lambda in
future. For, now these cases are hardcoded in the generic function

Resolves: #169991
2026-01-12 14:50:54 +00:00
Simon Pilgrim
7490901ea0
[ByteCode] InterpBuiltin.cpp - consistently use castAs<> if dereferencing the result (#174781)
castAs<> will at least assert the cast is valid while getAs<> will always just return nullptr and then explode
2026-01-07 16:23:12 +00:00
Timm Baeder
da5845d033
[clang][bytecode] Check builtin_memchr for non-block pointers earlier (#174192)
The getType() call might fail. We can't pull the isReadable() check up
though because that creates different diagnostic output compared to the
current interpreter.

Fixes #172202
2026-01-02 12:00:45 +01:00
Timm Baeder
db9549c4c0
[clang][bytecode] Check builtin_memchr() for one-past-end pointers (#174187)
We can't read from them and this fails later.

Fixes https://github.com/llvm/llvm-project/issues/173942
2026-01-02 10:50:55 +01:00
Timm Baeder
ed6698e28c
[clang][bytecode] Check builtin_memcpy() for non-block pointers (#174184)
This pretty hard to produce in C++ but easy in C.

Fixes #171609
2026-01-02 10:01:57 +01:00
sskzakaria
2c0565fcff
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow AVX512 mask predicate intrinsics to be used in constexpr (#173739)
Enables constexpr evaluation for the following AVX512 Integer Comparison Intrinsics:
```
_mm512_kmov

_mm_movm_epi8 _mm256_movm_epi8 _mm512_movm_epi8
_mm_movm_epi16 _mm256_movm_epi16 _mm512_movm_epi16
_mm_movm_epi32 _mm256_movm_epi32 _mm512_movm_epi32
_mm_movm_epi64 _mm256_movm_epi64 _mm512_movm_epi64
```
FIXES #162072
2025-12-28 15:47:03 +00:00
Abdelrehim, Ahmed Yaser Farouk
8bd5ba7af7
[Clang] Allow AVX/AVX2 lane permute operations in constexpr (#172149)
Resolves #169312 
Enables the usage of the following X86 intrinsics in `constexpr`:
```c
_mm256_permute2f128_pd	    _mm256_permute2f128_ps
_mm256_permute2f128_si256    _mm256_permute2x128_si256
```
2025-12-18 13:41:05 +00:00
Ahmed Nour
ed79fd714f
[Clang][x86]: allow PCLMULQDQ intrinsics to be used in constexpr (#169214)
Resolves #168741
2025-12-15 10:27:17 +00:00
Timm Bäder
773a6a9cc8 Revert "[clang][bytecode] Allocate InitMaps via Program/InterpState allocators (#170272)"
This reverts commit 8fe38c4c9c71c7a86ecdba476ee5bae4c02c0dfe.

This breaks the clang-armv7-2stage build bot:
https://lab.llvm.org/buildbot/#/builders/79/builds/2531
2025-12-09 06:19:09 +01:00
Aiden Grossman
392c302d79
[Clang] Fix unused variable warning from 1911ce132659222aee353882bd55… (#171223)
…70d689745a7d

These are only used in assertions so trigger warnings in release builds.
Fix this per the LLVM programming standards.
2025-12-08 23:25:09 +00:00
NagaChaitanya Vellanki
1911ce1326
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow GFNI intrinsics to be used in constexpr (#169619)
Resolves #169295
2025-12-08 22:18:41 +00:00
adbox53
95470b6c62
Replace interp__builtin_blend with interp__builtin_ia32_shuffle_gener… (#170217)
Fixes #169994

---------

Co-authored-by: Timm Baeder <tbaeder@redhat.com>
2025-12-08 08:24:51 +00:00
Timm Baeder
8fe38c4c9c
[clang][bytecode] Allocate InitMaps via Program/InterpState allocators (#170272)
Save them as a pointer intead of using a shared_ptr. This we we can use
the pointer integer value to differentiate the "no initmap yet" and "all
values initialzed" cases.

This regresses one test case in const-eval.c, but as it turns out, that
only worked coincidentally before.
2025-12-06 06:37:45 +01:00
Ahmed Nour
8f6e95ef45
[Clang][X86] Add constexpr support for permute4x64_pd and permute4x64_epi64 (#170442)
This PR adds constexpr support for the AVX2 cross-lane permute
intrinsics _mm256_permute4x64_pd and _mm256_permute4x64_epi64

Resolves https://github.com/llvm/llvm-project/issues/169304
2025-12-03 20:19:54 +00:00
Medha Tiwari
907c94b3c2
[X86][Clang] Add constexpr support for AVX512 kshift intrinsics (#170480)
Add AVX512 kshiftli/kshiftri mask intrinsics to be used in constexpr.

Enables constexpr evaluation for:
- `_kshiftli_mask8/16/32/64`
- `_kshiftri_mask8/16/32/64`

Fixes #162056
2025-12-03 18:38:40 +00:00
Hamza Hassanain
22d354a2f2
[X86][Clang] Support constexpr evaluation of cvtpd2ps intrinsics (#169980)
This patch implements constant evaluation support for the following X86
intrinsics:
- _mm_cvtpd_ps, _mm256_cvtpd_ps (Packed Double to Float)
- _mm_cvtsd_ss (Scalar Double to Float merge)
- Masked variants of the above

It implements the strict "Exact and Finite" rule: conversions that are
inexact, infinite, or NaN are rejected in constexpr contexts.

Fixes #169370
2025-12-03 11:59:37 +00:00
Timm Baeder
ff3d550d7e
[clang][bytecode][NFC] Add popToUInt64() to builtin evaluation (#170164)
We often don't need the APSInt at all, so add a version that pops the
integral from the stack and just static_casts to uint64_t.
2025-12-02 05:40:15 +01:00
Muhammad Abdul
dae9139d8f
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow AVX512 kmov intrinsics to be used in constexp (#169895)
Resolves #166975
2025-12-01 17:24:16 +00:00
Timm Baeder
48931e5e59
[clang][bytecode] Check memcmp builtin for one-past-the-end pointers (#170097)
We can't read from those and will run into an assertion sooner or later.

Fixes https://github.com/llvm/llvm-project/issues/170031
2025-12-01 12:43:35 +01:00
Islam Imad
246528cb3a
[clang][bytecode] Unify elementwise integer builtins using callback pattern (#169957)
This patch refactors the handling of elementwise integer unary
operations to use a unified callback-based approach, eliminating code
duplication.

Changes:
- Extended interp__builtin_elementwise_int_unaryop to handle vector types
- Replaced BI__builtin_elementwise_popcount with callback invocation
- Replaced BI__builtin_elementwise_bitreverse with callback invocation
- Removed  interp__builtin_elementwise_popcount function

The new approach uses a lambda function to specify the operation
(popcount or reverseBits), which is applied uniformly to both scalar and
vector operands. This reduces code duplication and makes it easier to
add similar builtins in the future.

Fixes #169657
2025-11-29 17:38:17 +00:00
NagaChaitanya Vellanki
f8e77168c8
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow PSLL/PSRA/PSRL var intrinsics to be used in constexpr (#169276)
Resolves #169176
2025-11-27 14:55:11 +00:00
Eric Xu
eee09ca984
[X86][Clang] Allow constexpr evaluation of F16C CVTPS2PH intrinsics (#162295)
Fixes #160312
2025-11-27 12:57:50 +00:00
NagaChaitanya Vellanki
c3c3d16773
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX512 VPMULTISHIFTQB intrinsics to be used in constexpr (#168995)
Resolves #167477
2025-11-27 10:26:32 +00:00
Moritz Zielke
954fa0f9ba
[Clang] Allow AVX/AVX512 subvector shuffles in constexpr (#168700)
Resolves #160514

Enables usage of the following x86 intrinsics in `constexpr`:

```
_mm256_shuffle_i64x2 _mm256_mask_shuffle_i64x2  _mm256_maskz_shuffle_i64x2 
_mm256_shuffle_f64x2 _mm256_mask_shuffle_f64x2  _mm256_maskz_shuffle_f64x2 
_mm512_shuffle_i64x2 _mm512_mask_shuffle_i64x2  _mm512_maskz_shuffle_i64x2 
_mm512_shuffle_f64x2 _mm512_mask_shuffle_f64x2  _mm512_maskz_shuffle_f64x2 

_mm256_shuffle_i32x4 _mm256_mask_shuffle_i32x4  _mm256_maskz_shuffle_i32x4 
_mm256_shuffle_f32x4 _mm256_mask_shuffle_f32x4  _mm256_maskz_shuffle_f32x4 
_mm512_shuffle_i32x4 _mm512_mask_shuffle_i32x4  _mm512_maskz_shuffle_i32x4 
_mm512_shuffle_f32x4 _mm512_mask_shuffle_f32x4  _mm512_maskz_shuffle_f32x4 
```
2025-11-26 17:34:21 +00:00
Timm Baeder
6459f39c37
[clang][bytecode] Add some convenience API to BitcastBuffer (#169516)
So we check the offsets before using them.
2025-11-26 06:36:58 +01:00
NagaChaitanya Vellanki
456ca91815
[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX512 VPSHUFBITQMB intrinsics to be used in constexpr (#168100)
Resolves #161337
2025-11-22 17:19:27 +00:00
stomfaig
2e424deeb6
[Clang][X86] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow VPERMILPD/S variable mask intrinsics to be used in constexpr (#168861)
Allowing VPERMILPD/S intrinsics to be used in constexpr

Closes #167878
2025-11-22 14:37:50 +00:00
Muhammad Abdul
7305b6eb54
[clang][X86] Allow VALIGND/Q element-shift intrinsics in constexpr evaluation (#168206)
Fixes #167681
2025-11-22 11:53:34 +00:00
sskzakaria
a2b4c0fbe0
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow AVX512 mask predicate intrinsics to be used in constexpr (#165054)
Enables constexpr evaluation for the following AVX512 Instrinsics:
```
_mm_movepi8_mask _mm256_movepi8_mask _mm512_movepi8_mask
_mm_movepi16_mask _mm256_movepi16_mask _mm512_movepi16_mask
_mm_movepi32_mask _mm256_movepi32_mask _mm512_movepi32_mask
_mm_movepi64_mask _mm256_movepi64_mask _mm512_movepi64_mask
```
Part of #162072
2025-11-20 11:25:23 +00:00
stomfaig
50791c3a70
[Clang][X86] allow VPERMILPD/S imm intrinsics to be used in constexpr (#168044)
Resolves #166529
2025-11-19 11:50:16 +00:00
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