10051 Commits

Author SHA1 Message Date
Simon Pilgrim
4da69721f9 [X86] test_mm512_mask_fmadd_ps - add missing select checks 2025-08-21 10:27:06 +01:00
Simon Pilgrim
e4b110ab9f
[Headers][X86] Allow FMA3/FMA4 vector intrinsics to be used in constexpr (#154558)
Now that #152455 is done, we can make all the vector fma intrinsics that wrap __builtin_elementwise_fma to be constexpr

Fixes #154555
2025-08-21 09:09:40 +01:00
Joseph Huber
9888f0c3c4
[Clang] Add builtins for masked vector loads / stores (#154464)
Summary:
Clang has support for boolean vectors, these builtins expose the LLVM
instruction of the same name. This differs from a manual load and select
by potentially suppressing traps from deactivated lanes.

Fixes: https://github.com/llvm/llvm-project/issues/107753
2025-08-20 13:33:32 -05:00
Chaitanya Koparkar
f649605bcf
[clang] Enable constexpr handling for __builtin_elementwise_fma (#152919)
Fixes https://github.com/llvm/llvm-project/issues/152455.
2025-08-20 14:51:40 +01:00
Fraser Cormack
8b128388b5
[clang] Introduce elementwise ctlz/cttz builtins (#131995)
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
2025-08-20 12:18:28 +01:00
Kerry McLaughlin
c34cba0413
[AArch64][SME] Lower aarch64.sme.cnts* to vscale when in streaming mode (#154305)
In streaming mode, both the @llvm.aarch64.sme.cnts and @llvm.aarch64.sve.cnt
intrinsics are equivalent. For SVE, cnt* is lowered in instCombineIntrinsic
to @llvm.sme.vscale(). This patch lowers the SME intrinsic similarly when
in streaming-mode.
2025-08-20 09:48:36 +01:00
Brandon Wu
52a2e68fda
[clang][RISCV] Fix crash on VLS calling convention (#145489)
This patch handle struct of fixed vector and struct of array of fixed
vector correctly for VLS calling convention in EmitFunctionProlog,
EmitFunctionEpilog and EmitCall.

stack on: https://github.com/llvm/llvm-project/pull/147173
2025-08-20 16:39:02 +08:00
Michael Buch
3f3bc4853e
[clang][test][DebugInfo] Move debug-info tests from CodeGen to DebugInfo directory (#154311)
This patch works towards consolidating all Clang debug-info into the
`clang/test/DebugInfo` directory
(https://discourse.llvm.org/t/clang-test-location-of-clang-debug-info-tests/87958).

Here we move only the `clang/test/CodeGen` tests.

The list of files i came up with is:
1. searched for anything with `*debug-info*` in the filename
2. searched for occurrences of `debug-info-kind` in the tests

I created a couple of subdirectories in `clang/test/DebugInfo` where I
thought it made sense (mostly when the tests were target-specific).

There's a couple of tests in `clang/test/CodeGen` that still set
`-debug-info-kind`. They probably don't need to do that, but I'm not
changing that as part of this PR.
2025-08-19 18:25:13 +01:00
Simon Pilgrim
355b747acd
[Headers][X86] Enable constexpr handling for pmulhw/pmulhuw avx512 mask/maskz intrinsics (#154341)
Followup to #152524 / #152540 - allow the predicated variants to be used in constexpr as well
2025-08-19 15:55:16 +01:00
Aditi Medhane
948abf1bf5
[PowerPC] Add BCDCOPYSIGN and BCDSETSIGN Instruction Support (#144874)
Support the following BCD format conversion builtins for PowerPC.

- `__builtin_bcdcopysign` – Conversion that returns the decimal value of
the first parameter combined with the sign code of the second parameter.
`
- `__builtin_bcdsetsign` – Conversion that sets the sign code of the
input parameter in packed decimal format.

> Note: This built-in function is valid only when all following
conditions are met:
> -qarch is set to utilize POWER9 technology.
> The bcd.h file is included.

## Prototypes

```c
vector unsigned char __builtin_bcdcopysign(vector unsigned char, vector unsigned char);
vector unsigned char __builtin_bcdsetsign(vector unsigned char, unsigned char);
```

## Usage Details

`__builtin_bcdsetsign`: Returns the packed decimal value of the first
parameter combined with the sign code.
The sign code is set according to the following rules:
- If the packed decimal value of the first parameter is positive, the
following rules apply:
     - If the second parameter is 0, the sign code is set to 0xC.
     - If the second parameter is 1, the sign code is set to 0xF.
- If the packed decimal value of the first parameter is negative, the
sign code is set to 0xD.
> notes:
>     The second parameter can only be 0 or 1.
> You can determine whether a packed decimal value is positive or
negative as follows:
> - Packed decimal values with sign codes **0xA, 0xC, 0xE, or 0xF** are
interpreted as positive.
> - Packed decimal values with sign codes **0xB or 0xD** are interpreted
as negative.

---------

Co-authored-by: Aditi-Medhane <aditi.medhane@ibm.com>
2025-08-19 14:47:27 +05:30
Simon Pilgrim
9adc4f9720
[X86] Enable MMX unpcklo/unpckhi intrinsics in constexpr (#154149)
Matches behaviour in SSE/AVX/AVX512 intrinsics - was missed in #153028
2025-08-19 09:08:39 +01:00
Simon Pilgrim
36f911173a [X86] avx512vlbw-builtins.c - add C/C++ test coverage 2025-08-18 10:30:15 +01:00
Simon Pilgrim
6036e5d0d7 [X86] avx512vlbw-reduceIntrin.c - add C/C++ and -fno-signed-char test coverage 2025-08-18 10:30:14 +01:00
Timm Baeder
0d05c42b6a
[clang][bytecode] Improve __builtin_{,dynamic_}object_size implementation (#153601) 2025-08-18 11:12:33 +02:00
Simon Pilgrim
ce5276f61c
[Clang][X86] Add avx512 __builtin_ia32_select* constexpr handling (#152705)
This should allow us to constexpr many avx512 predicated intrinsics where they wrap basic intrinsics that are already constexpr

Fixes #152321
2025-08-18 09:37:20 +01:00
Brandon Wu
98f4b7797e
[RISCV][llvm] Support fixed-length vector inline assembly constraints (#150724) 2025-08-18 03:36:12 +00:00
Pedro Lobo
d42a1d405d
[Headers][X86] Allow pmuludq/pmuldq to be used in constexpr (#153293)
Adds `constexpr` support for `pmuludq` and `pmuldq` intrinsics.

Closes #153002.
Part of #30794.
2025-08-18 00:32:33 +01:00
Simon Pilgrim
92cb0414ca [X86] avx512vnni-builtins.c / avx512vlvnni-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 17:55:33 +01:00
Simon Pilgrim
2c20a9bfb3 [X86] avx512bf16-builtins.c / avx512vlbf16-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 17:38:43 +01:00
Simon Pilgrim
38eb14f27c [X86] avx512vbmi2-builtins.c / avx512vlvbmi2-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 16:35:16 +01:00
Simon Pilgrim
7df862818e [X86] avx512vbmi-builtins.c / avx512vbmivl-builtin.c - add C/C++ and 32/64-bit test coverage 2025-08-15 16:35:15 +01:00
Simon Pilgrim
09267f6720 [X86] avx512vp2intersect-builtins.c / avx512vlvp2intersect-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 15:39:12 +01:00
Simon Pilgrim
17dd57b00e [X86] avxvnni-builtins.c / avxvnniint8-builtins.c / avxvnniint16-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 15:17:15 +01:00
Simon Pilgrim
6ad39bc866 [X86] avxifma-builtins.c / avx512ifma-builtins.c / avx512ifmavl-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 12:09:54 +01:00
Simon Pilgrim
b014d10ed7 [X86] avx512cd-builtins.c + avx512vlcd-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 09:44:18 +01:00
Ami-zhang
a1b6e7ff39
[clang][LoongArch] Ensure target("lasx") implies LSX support (#153542)
Currently, `__attribute__((target("lasx")))` does not automatically
enable LSX support, causing Clang to fail with `-mno-lsx`. Since
LASX depends on LSX, enabling LASX should implicitly enable LSX to
avoid clang error.
    
Fixes #149512.

Depends on #153541
2025-08-15 09:53:08 +08:00
Ami-zhang
793a6b4fd4
[NFC] Precommit test for issue #149512 (#153541) 2025-08-15 09:15:15 +08:00
Bill Wendling
aa4805a090
[Clang][attr] Add 'cfi_salt' attribute (#141846)
The 'cfi_salt' attribute specifies a string literal that is used as a
"salt" for Control-Flow Integrity (CFI) checks to distinguish between
functions with the same type signature. This attribute can be applied
to function declarations, function definitions, and function pointer
typedefs.

This attribute prevents function pointers from being replaced with
pointers to functions that have a compatible type, which can be a CFI
bypass vector.

The attribute affects type compatibility during compilation and CFI
hash generation during code generation.

  Attribute syntax: [[clang::cfi_salt("<salt_string>")]]
  GNU-style syntax: __attribute__((cfi_salt("<salt_string>")))

- The attribute takes a single string of non-NULL ASCII characters.
- It only applies to function types; using it on a non-function type
  will generate an error.
- All function declarations and the function definition must include
  the attribute and use identical salt values.

Example usage:

  // Header file:
  #define __cfi_salt(S) __attribute__((cfi_salt(S)))

  // Convenient typedefs to avoid nested declarator syntax.
  typedef int (*fp_unsalted_t)(void);
  typedef int (*fp_salted_t)(void) __cfi_salt("pepper");

  struct widget_ops {
    fp_unsalted_t init;     // Regular CFI.
    fp_salted_t exec;       // Salted CFI.
    fp_unsalted_t teardown; // Regular CFI.
  };

  // bar.c file:
  static int bar_init(void) { ... }
  static int bar_salted_exec(void) __cfi_salt("pepper") { ... }
  static int bar_teardown(void) { ... }

  static struct widget_generator _generator = {
    .init = bar_init,
    .exec = bar_salted_exec,
    .teardown = bar_teardown,
  };

  struct widget_generator *widget_gen = _generator;

  // 2nd .c file:
  int generate_a_widget(void) {
    int ret;

    // Called with non-salted CFI.
    ret = widget_gen.init();
    if (ret)
      return ret;

    // Called with salted CFI.
    ret = widget_gen.exec();
    if (ret)
      return ret;

    // Called with non-salted CFI.
    return widget_gen.teardown();
  }

Link: https://github.com/ClangBuiltLinux/linux/issues/1736
Link: https://github.com/KSPP/linux/issues/365

---------

Signed-off-by: Bill Wendling <morbo@google.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-08-14 13:07:38 -07:00
Mikołaj Piróg
768eae72cd
[Clang] Honor -flax-vector-conversions=none on some tests (#153433)
As in title. This is done as a step towards enabling the
`-flax-vector-conversions=none` globally as a default
2025-08-14 17:02:52 +02:00
Simon Pilgrim
179698a0fb [X86] ssse3-builtins.c - add -fno-signed-char test coverage 2025-08-14 14:20:35 +01:00
Vincent
d3bbdc7bde
[clang] constexpr __builtin_elementwise_abs support (#152497)
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>
2025-08-14 12:34:23 +01:00
TianYe
44e6bc6fc0
[Headers][X86] Allow AVX2/AVX512 broadcast intrinsics to be used in Constexpr (#153363)
Fix [issue](https://github.com/llvm/llvm-project/issues/152499)
This patch adds support for the following broadcast intrinsics
by wrapping them around existing generic shuffle implementations:
```
_mm_broadcastb_epi8
_mm_broadcastw_epi16
_mm_broadcastd_epi32
_mm_broadcastq_epi64
_mm_broadcastss_ps
_mm_broadcastsd_pd

_mm256_broadcastb_epi8
_mm256_broadcastw_epi16
_mm256_broadcastd_epi32
_mm256_broadcastq_epi64
_mm256_broadcastss_ps
_mm256_broadcastsd_pd

_mm256_broadcastsi128_si256

_mm512_broadcastb_epi8
_mm512_broadcastw_epi16
_mm512_broadcastd_epi32
_mm512_broadcastq_epi64
_mm512_broadcastss_ps
_mm512_broadcastsd_pd

_mm512_broadcast_f32x2 _mm256_broadcast_f32x2
_mm512_broadcast_i32x2 _mm256_broadcast_i32x2 _mm_broadcast_i32x2
_mm512_broadcast_f32x4 _mm256_broadcast_f32x4
_mm512_broadcast_i32x4 _mm256_broadcast_i32x4
_mm512_broadcast_f32x8
_mm512_broadcast_i32x8
_mm512_broadcast_f64x2 _mm256_broadcast_f64x2
_mm512_broadcast_i64x2 _mm256_broadcast_i64x2
_mm512_broadcast_f64x4
_mm512_broadcast_i64x4
```

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-14 09:40:11 +01:00
Oliver Hunt
d8850ee6c0
[clang][Obj-C][PAC] Add support for authenticating block metadata (#152978)
Introduces the use of pointer authentication to protect the invocation,
copy and dispose, reference, and descriptor pointers in Objective-C
block objects.

Resolves #141176
2025-08-13 22:01:24 -07:00
Jasmine Tang
da422daea9
Fix wrong function signature for #153102 (#153473)
- Fixes wrong function signature for #153102
2025-08-13 13:58:52 -07:00
Martin Storsjö
ddd4974297
[clang] [test] Improve XFAIL patterns for aarch64 msvc (#153397)
Unless relevant (which it very seldom is), avoid checking specifically
for the "pc" vendor field; mingw environments often use "w64" as vendor
- but not always.

In this case, this test has been passing in mingw configurations lately;
the previous XFAIL pattern would cause the test to unexpectedly succeed
if running with a triple with a "pc" vendor field.

Instead reinstate the checking for an -msvc environment here; this
essentially reverts 8e029d9e35092d1440dafc8991e73fb8c3b323d7 (and the
related typo fix 301f3da5162499965287338a0cd52309fb28e8b8).

I'm not sure how 8e029d9e35092d1440dafc8991e73fb8c3b323d7 concluded that
this issue affected the gnu ABI (mingw) as well; I rechecked building
that commit, and at that point, this test did pass for an aarch64 mingw
target. (Due to the -pc- triple, the false positive XFAIL match hasn't
been noticed before.)
2025-08-13 21:57:00 +03:00
Jasmine Tang
be5554d610
[Headers][X86] Allow SSE/AVX/AVX512 unpck intrinsics to be used in constexpr (#153102)
Fixes https://github.com/llvm/llvm-project/issues/153028
2025-08-13 09:42:41 -07:00
Simon Pilgrim
9ce3aff0c3 [X86] avx512bw-builtins.c - add C/C++ test coverage
Catches a typo in the _mm512_adds_epu8 constexpr test
2025-08-13 13:54:18 +01:00
Simon Pilgrim
5c95b83644 [X86] builtin_test_helpers.h - ensure the match_v*qi matchers work with -fno-signed-char tests
Work with explicit signed char types to avoid signed/unsigned char truncation out of bounds warnings
2025-08-13 13:54:17 +01:00
Simon Pilgrim
11186afcc8 [X86] avx512bw-builtins.c - avoid _mm256_setr_epi8 inside constexpr tests
Avoid nested intrinsics in constexpr tests - use __32qs instead to work correctly with -fno-signed-char tests
2025-08-13 13:54:17 +01:00
Simon Pilgrim
11ef62f087
[X86] Check the exact fp bits and not just fp equality for constexpr tests (#153383)
We missed several +/-0.0 comparison mismatches due to only doing equality checks
2025-08-13 13:34:55 +01:00
Simon Pilgrim
4e10b62442 [X86] avx512vldq-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-13 11:40:27 +01:00
Yatao Wang
a9a0978c1d
[Headers][X86] Allow MMX/SSE2/AVX2/AVX512BW integer saturated arithmetic intrinsics to be used in constexpr (#153088)
This PR allows the following MMX/SSE2/AVX2/AVX512BW integer saturated arithmetic intrinsics to be used in constexpr
```
_mm_adds_pi8
_mm_adds_pi16
_mm_subs_pi8
_mm_subs_pi16

_mm_adds_pu8
_mm_adds_pu16
_mm_subs_pu8
_mm_subs_pu16

_mm_adds_epi8
_mm_adds_epi16
_mm_subs_epi8
_mm_subs_epi16

_mm_adds_epu8
_mm_adds_epu16
_mm_subs_epu8
_mm_subs_epu16

_mm256_adds_epi8
_mm256_adds_epi16
_mm256_subs_epi8
_mm256_subs_epi16

_mm256_adds_epu8
_mm256_adds_epu16
_mm256_subs_epu8
_mm256_subs_epu16

_mm512_adds_epi8
_mm512_adds_epi16
_mm512_subs_epi8
_mm512_subs_epi16

_mm512_adds_epu8
_mm512_adds_epu16
_mm512_subs_epu8
_mm512_subs_epu16
```

Fixes #152506

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-13 10:27:40 +01:00
Simon Pilgrim
267f592ca0
[Headers][X86] Allow _mm_cmov_si128/_mm256_cmov_si256 intrinsics to be used in constexpr (#153236) 2025-08-13 08:53:26 +01:00
Daniel Paoliello
fc2146ef31
[win][arm64ec] Handle Arm64EC for Clang CodeGen tests that current XFAIL AArch64 Windows (#153255)
* `c-strings.c` - add an `XFAIL` for Arm64EC and add a comment to
explain the failure.
* `volatile-1.c` - add a regex for alignment during loads.
2025-08-12 16:12:49 -07:00
moorabbit
f8653cecd1
[Clang][X86] Replace F16C vcvtph2ps/256 intrinsics with (convert|shuffle)vector builtins (#152911)
The following intrinsics were replaced by a combination of
`__builtin_shufflevector` and `__builtin_convertvector`:
- `__builtin_ia32_vcvtph2ps`
- `__builtin_ia32_vcvtph2ps256`

Fixes #152749
2025-08-12 16:32:19 +01:00
Simon Pilgrim
bd3aa88802
[Headers][X86] Allow SSE MOVD/Q scalar<->vector cvt intrinsics to be used in constexpr (#153192) 2025-08-12 15:29:16 +01:00
Simon Pilgrim
72b53cde1c [X86] xop-builtins.c - add C/C++ test coverage 2025-08-12 14:44:10 +01:00
Simon Pilgrim
9442b4ea25 [X86] mmx-builtins.c - use __v8qs initializer instead of _mm_setr_pi8 to correctly run on -fno-signed-char targets 2025-08-12 14:44:10 +01:00
Chaitanya Koparkar
c3bf73bc4a
[clang] Add elementwise fshl/fshr builtins (#153113)
This patch implements `__builtin_elementwise_fshl` and
`__builtin_elementwise_fshr` builtins.

These map to the fshl/fshr intrinsics described here:
- https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic
- https://llvm.org/docs/LangRef.html#llvm-fshr-intrinsic

Fixes https://github.com/llvm/llvm-project/issues/152555.
2025-08-12 20:57:55 +09:00
Iris Shi
713ec58dec
[clang] constexpr integer __builtin_elementwise_{max,min} (#152294)
- Closes #152278
- Part of #51787

This PR adds support for the bulitin elementwise max/min functions for
integer types.
2025-08-12 09:49:05 +08:00