Age | Commit message (Collapse) | Author | Files | Lines |
|
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
|
|
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.
|
|
Fixes #157492
|
|
pack intrinsics to be used in constexpr (#156003)
Fixes #154283
|
|
(#159998)
Fixes #158646
|
|
Summary:
The added bit counting builtins for vectors used `cttz` and `ctlz`,
which is consistent with the LLVM naming convention. However, these are
clang builtins and implement exactly the `__builtin_ctzg` and
`__builtin_clzg` behavior. It is confusing to people familiar with other
other builtins that these are the only bit counting intrinsics named
differently. This includes the additional operation for the undefined
zero case, which was added as a `clzg` extension.
|
|
AVX/AVX512 subvector insertion intrinsics to be used in constexpr #157709 (#158778)
AVX/AVX512 vector insert intrinsics now support constexpr evaluation in both the AST evaluator and bytecode interpreter paths.
FIXES: #157709
|
|
If it's truly a known const int, it won't emit any diagnostics anyway.
And if it did, we wouldn't notice because no call site passed something
non-null.
|
|
NFC. (#159330)
This avoids the following warnings:
../../clang/lib/AST/ExprConstant.cpp: In member function ‘bool {anonymous}::IntExprEvaluator::VisitBuiltinCallExpr(const clang::CallExpr*, unsigned int)’:
../../clang/lib/AST/ExprConstant.cpp:14104:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
14104 | }
| ^
../../clang/lib/AST/ExprConstant.cpp:14105:3: note: here
14105 | case Builtin::BIstrlen:
| ^~~~
../../clang/lib/Driver/ToolChains/CommonArgs.cpp: In function ‘std::string clang::driver::tools::complexRangeKindToStr(clang::LangOptionsBase::ComplexRangeKind ’:
../../clang/lib/Driver/ToolChains/CommonArgs.cpp:3523:1: warning: control reaches end of non-void function [-Wreturn-type]
3523 | }
| ^
|
|
Instead of having `State::getLangOpts()`, which does a virtual call to
`getASTContext()` to call `getLangOpts()` on that, just move
`getLangOpts()` to the subclasses so we can do that without the virtual
call. We never call `getLangOpts()` in `State.cpp`, so it's not needed
in the base class.
|
|
Both the expression (the initializer) as well as the VarDecl can't be
null here. Assert that.
|
|
This is not implemented at compile time and asserts in assertion builds,
so reject it here.
Fixed the coding style in `BuiltinShuffleVector` at the same time.
Fixes #158471
|
|
(#157776)
This marks the following builtins as constexpr, which allows their
corresponding intrinsics to be used in constexprs.
| Intrinsics | X86 Builtins | CPUID Flags | Header |
| -------------------- | --------------------------- | ----------- |
----------- |
| `_mm_blend_pd` | `__builtin_ia32_blendpd` | SSE4.1 | smmintrin.h |
| `_mm256_blend_pd` | `__builtin_ia32_blendpd256` | AVX | immintrin.h |
| `_mm_blend_ps` | `__builtin_ia32_blendps` | SSE4.1 | smmintrin.h |
| `_mm256_blend_ps` | `__builtin_ia32_blendps256` | AVX | immintrin.h |
| `_mm_blend_epi16` | `__builtin_ia32_pblendw128` | SSE4.1 | smmintrin.h
|
| `_mm256_blend_epi16` | `__builtin_ia32_pblendw256` | AVX2 |
immintrin.h |
| `_mm_blend_epi32` | `__builtin_ia32_pblendd128` | AVX2 | immintrin.h |
| `_mm256_blend_epi32` | `__builtin_ia32_pblendd256` | AVX2 |
immintrin.h |
Fixes #157065
---------
Co-authored-by: Timm Baeder <tbaeder@redhat.com>
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
|
|
We just called `getInit()`, which isn't always correct and used the
wrong initializer in the module test case.
|
|
Set the EvalMode on InterpState and abort when initalizing a global
temporary, like the current interpreter does. The rest is just plumbing
in EvaluateAsLValue.
Fixes #157497
|
|
Make it an enum class and move the enum to State.h as well as the
`EvalMode` member to `State`. This is in preparation of using the
evaluation mode from `InterpState` as well.
|
|
We don't need a mutable `ASTContext` here.
|
|
intrinsics (#157464)
This PR updates the avg builtins to support constant expression handling, by extending the VectorExprEvaluator::VisitCallExpr that handles elementwise integer binop builtins.
Closes #155390
---------
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
|
|
intrinsics to be used in constexpr (#157681)
Extends interp__builtin_elementwise_triop to handle (vector, vector, scalar) trinary op intrinsics
Fixes #153152
|
|
constexpr (#157696)
Handle missing AVX512F epi64 and AVX512BW epi16 cases with existing code paths
Fixes #154287
|
|
repeated switch statement (#157137)
Create a EvaluateBinOpExpr helper that each related group of elementwise
binop builtins can use with their own custom callback, to help reduce
the amount of duplication and avoid too much code bloat as more builtins
are added.
This also handles builtins which have a elementwise LHS operand and a
scalar RHS operand.
Similar to #155891 which did the same thing for the new ByteCode eval.
|
|
Instead of relaying from InterpState to the parent state (which is an
EvalInfo), just save the variables in State instead, so both subclasses
have access to it.
|
|
(#157126)
BLENDV intrinsics use the signbit of the condition mask to select
between the LHS (false) and RHS (true) operands
Fixes #157066
|
|
(#157100)
BLENDV intrinsics use the signbit of the condition mask to select between the LHS (false) and RHS (true) operands
First part of #157066 - the BLENDVPS/D requires floatbits hacking which I need to do some prep work for
|
|
Fixes #153151.
|
|
(#155080)
fix: #151716
In #65918, support of incomplete array type is added in
TryReferenceListInitialization. It causes the crash in Constant Expr
Calculation since it only considers the case where it is
ConstantArrayType.
This patch wants to add support for incomplete array type also.
|
|
to be used in constexpr (#156480)
Followup to #154780
|
|
6a60f18997d62b0e2842a921fcb6beb3e52ed823 fixed the primary issue of
dereferences, but there are some expressions that depend on the identity
of the pointed-to object without actually accessing it. Handle those
cases.
Also, while I'm here, fix a crash in interpreter mode comparing typeid
to nullptr.
|
|
This implements support for [named
loops](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm) for
C2y.
When parsing a `LabelStmt`, we create the `LabeDecl` early before we parse
the substatement; this label is then passed down to `ParseWhileStatement()`
and friends, which then store it in the loop’s (or switch statement’s) `Scope`;
when we encounter a `break/continue` statement, we perform a lookup for
the label (and error if it doesn’t exist), and then walk the scope stack and
check if there is a scope whose preceding label is the target label, which
identifies the jump target.
The feature is only supported in C2y mode, though a cc1-only option
exists for testing (`-fnamed-loops`), which is mostly intended to try
and make sure that we don’t have to refactor this entire implementation
when/if we start supporting it in C++.
---------
Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
|
|
(#156047)
|
|
Fixes #154293
Implement VectorExprEvaluator::VisitCallExpr constexpr support for left, right, arithmetic shift for MMX/SSE/AVX2/AVX512 intrinsics
_mm*_slli_epi*
_mm*_srli_epi*
_mm*_srai_epi*
_mm*_mask_slli_epi*
_mm*_maskz_slli_epi*
NOTE: not all intrinsics have all widths i.e. _mm_srli_pi32 doesn't have pi64 etc.
|
|
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`,
as a redirection to `TypeBase.h`, and redirects most users to include
the former instead.
This is a preparatory patch for being able to provide inline definitions
for `Type` methods which would otherwise cause a circular dependency
with `Decl{,CXX}.h`.
Doing these operations into their own NFC patch helps the git rename
detection logic work, preserving the history.
This patch makes clang just a little slower to build (~0.17%), just
because it makes more code indirectly include `DeclCXX.h`.
|
|
This is a preparatory patch, to be able to provide inline definitions
for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also
depends on `Type.h`, this would not be possible without some
reorganizing.
Splitting this rename into its own patch allows git to track this as a
rename, and preserve all git history, and not force any code
reformatting.
A later NFC patch will reintroduce `Type.h` as redirection to
`TypeBase.h`, rewriting most places back to directly including `Type.h`
instead of `TypeBase.h`, leaving only a handful of places where this is
necessary.
Then yet a later patch will exploit this by making more stuff inline.
|
|
It can be null, when called via CheckICE().
Accidentally introduced via #119366
Fixes #155507
|
|
|
|
1) Return `std::nullopt` instead of `{}`.
2) Rename the new function to evaluate*, it's not a simple getter.
|
|
TagDecls (#155463)
And make use of those.
These changes are split from prior PR #155028, in order to decrease the
size of that PR and facilitate review.
|
|
Summary:
Boolean vectors as implemented in clang can be bit-casted to an integer
that is rounded up to the next primitive sized integer. Users can do
this themselves, but since the counting bits are very likely to be used
with bitmasks like this and the generic forms are expected to be
generic it seems reasonable that we handle this case directly.
|
|
This changes a bunch of places which use getAs<TagType>, including
derived types, just to obtain the tag definition.
This is preparation for #155028, offloading all the changes that PR used
to introduce which don't depend on any new helpers.
|
|
Check for missing VLA size expressions (e.g. in int a[*][10]) before
evaluation to avoid crashes in _Countof and constant expression checks.
Fixes #152826
|
|
Warns about calls to functions decorated with attribute `alloc_size`
that specify insufficient size for the type they are cast to. Matches
the behavior of the GCC option of the same name.
Closes #138973
---------
Co-authored-by: Vladimir Vuksanovic <vvuksano@cisco.com>
|
|
`RecordExprEvaluator::VisitCXXConstructExpr()` (#154610)
When initializing an anonymous struct via an `IndirectFieldDecl`, we
create an `APValue` for the struct, but we leave the fields
uninitialized. This would later cause the `CXXConstructExpr` that
initializes the anonymous struct member to not do anything since its
`APValue` already had a value (but the member didn't). Just remove the
check for an `APValue` that already has a value from
`RecordExprEvaluator::VisitCXXConstructExpr()`.
Fixes #154567
|
|
This handles constant folding for the AVX2 per-element shift intrinsics, which handle out of bounds shift amounts (logical result = 0, arithmetic result = signbit splat)
AVX512 intrinsics will follow in follow up patches
First stage of #154287
|
|
Fixes https://github.com/llvm/llvm-project/issues/152455.
|
|
These builtins are modeled on the clzg/ctzg builtins, which accept an
optional second argument. This second argument is returned if the first
argument is 0. These builtins unconditionally exhibit zero-is-undef
behaviour, regardless of target preference for the other ctz/clz
builtins. The builtins have constexpr support.
Fixes #154113
|
|
|
|
This should allow us to constexpr many avx512 predicated intrinsics where they wrap basic intrinsics that are already constexpr
Fixes #152321
|
|
Adds `constexpr` support for `pmuludq` and `pmuldq` intrinsics.
Closes #153002.
Part of #30794.
|
|
Added constant evaluation support for `__builtin_elementwise_abs` on integer, float and vector type.
fixes #152276
---------
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
|
|
- Closes #152278
- Part of #51787
This PR adds support for the bulitin elementwise max/min functions for
integer types.
|