129 Commits

Author SHA1 Message Date
Andrzej Warzyński
1d13412cd3
[clang][nfc] Remove else after return in ARM.cpp (#180733)
Align with the LLVM coding standard:
* https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
2026-02-10 16:35:52 +00:00
Andrzej Warzyński
80677dc5e0
[CIR][NEON] Add lowering support for vceqzd_s64 (#179779)
Rather than creating a dedicated ClangIR test file, the original test file for
this intrinsic is effectively reused:

  * clang/test/CodeGen/AArch64/neon-intrinsics.c

“Effectively” meaning that the corresponding test is moved (rather than
literally reused) to a new file within the original AArch64 builtins test
directory:

  * clang/test/CodeGen/AArch64/neon/intrinsics.c

This is necessary to avoid lowering unsupported examples from intrinsics.c with
`-fclangir`. The new file will eventually replace the original one once all
builtins from it can be lowered via ClangIR.

To facilitate test re-use, new LIT "feature" is added so that CIR tests can be
run conditionally, e.g. the following will only run when `CLANG_ENABLE_CIR` is
set:
```C
// RUN: %if cir %{%clang_cc1 ... %}
```
This sort of substitutions are documented in [2].

REFERENCES:
[1] https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:@navigationhierarchiessimdisa=[Neon]&q=vceqzd_s64
[2] https://llvm.org/docs/TestingGuide.html#substitutions
2026-02-09 18:48:42 +00:00
Simon Pilgrim
1d61ac2d41
[clang][amdgpu] mapCABIAtomicOrdering - fix MSVC not all control paths return a value warning. NFC. (#180500) 2026-02-09 10:59:37 +00:00
Pierre van Houtryve
b79ba02479
[AMDGPU][GFX12.5] Reimplement monitor load as an atomic operation (#177343)
Load monitor operations make more sense as atomic operations, as
non-atomic operations cannot be used for inter-thread communication w/o
additional synchronization.
The previous built-in made it work because one could just override the
CPol bits, but that bypasses the memory model and forces the user to learn
about ISA bits encoding.

Making load monitor an atomic operation has a couple of advantages.
First, the memory model foundation for it is stronger. We just lean on the
existing rules for atomic operations. Second, the CPol bits are abstracted away
from the user, which avoids leaking ISA details into the API.

This patch also adds supporting memory model and intrinsics
documentation to AMDGPUUsage.

Solves SWDEV-516398.
2026-02-09 09:57:27 +01:00
Demetrius Kanios
24c7a10730
[Clang][WebAssembly] Fix WASM tables to allow __funcref function pointers (#178720)
Allows __funcref pointers to be used as the element type for WASM tables
in Clang (static, global, zero-length arrays of a reference type).
Modifies `QualType::isWebAssemblyFuncrefType` to correctly look at the
addrspace of the pointee, rather than the pointer type.

Related: #140933
2026-02-04 09:55:36 -08:00
Aaditya
f190477718
[AMDGPU] Add builtins for wave reduction intrinsics (#170813) 2026-01-30 18:15:06 +05:30
Craig Topper
05e2ee9664
[RISCV] Replace riscv.clmul intrinsic with llvm.clmul (#178092)
I did not replace riscv.clmulh/clmulr since those require a multiple
instruction pattern match. I wanted to ensure that -O0 will select the
correct instructions without relying on combines.
2026-01-26 21:12:48 -08:00
Srinivasa Ravi
13205c51fc
[clang][NVPTX] Add missing half-precision add/mul/fma intrinsics (#170079)
This change adds the following missing half-precision
add/sub/fma intrinsics for the NVPTX target:
- `llvm.nvvm.add.rn{.ftz}.sat.f16`
- `llvm.nvvm.add.rn{.ftz}.sat.v2f16`
- `llvm.nvvm.mul.rn{.ftz}.sat.f16`
- `llvm.nvvm.mul.rn{.ftz}.sat.v2f16`
- `llvm.nvvm.fma.rn.oob.*`

We lower `fneg` followed by one of the above addition 
intrinsics to the corresponding `sub` instruction.

This also removes some incorrect `bf16` fma intrinsics with no
valid lowering.

PTX spec reference:
https://docs.nvidia.com/cuda/parallel-thread-execution/#half-precision-floating-point-instructions
2026-01-20 17:56:55 +05:30
Maryam Moghadas
196548988e
[PowerPC] Add support for AMO store builtins (#170933)
This commit adds 4 Clang builtins for PowerPC AMO store operations:

__builtin_amo_stwat for 32-bit unsigned operations
__builtin_amo_stdat for 64-bit unsigned operations
__builtin_amo_stwat_s for 32-bit signed operations
__builtin_amo_stdat_s for 64-bit signed operations

and maps GCC's AMO store functions to these Clang builtins for
compatibility.
2026-01-19 10:58:32 -05:00
Maryam Moghadas
6f8a7e79db
[PowerPC] Add AMO load builtins for conditional increment/decrement (#169435)
This commit adds 4 Clang builtins for PowerPC AMO load conditional 
increment and decrement operations: 

 __builtin_amo_lwat_cond for 32-bit unsigned operations
 __builtin_amo_ldat_cond for 64-bit unsigned operations
 __builtin_amo_lwat_cond_s for 32-bit signed operations
 __builtin_amo_ldat_cond_s for 64-bit signed operations
2026-01-16 12:11:45 -05:00
Kerry McLaughlin
04e5bc7dfb
[AArch64] Add support for range prefetch intrinsic (#170490)
This patch adds support in Clang for the RPRFM instruction, by adding
the following intrinsics:

```
void __pldx_range(unsigned int *access_kind*, unsigned int retention_policy,
                               signed int length*, unsigned int count, signed int stride,
                               size_t reuse distance,  void const *addr);

void __pld_range(unsigned int access_kind*, unsigned int retention_policy,
                              uint64_t metadata, void const *addr);
```

The `__ARM_PREFETCH_RANGE` macro can be used to test whether these
intrinsics are implemented. If the RPRFM instruction is not available, this
instruction is a NOP.

This implements the following ACLE proposal:
https://github.com/ARM-software/acle/pull/423
2026-01-12 15:53:17 +00:00
Haocong Lu
e0cf581ad4
[Clang][X86] Remove useless extractvalue on aesencwide/aesdecwide builtin CodeGen (#175113)
This is a pre-commit of CIR codegen for `aesencwide/aesdecwide` builtin,
remove useless `extractvalue` on clang CodeGen for this builtin.
2026-01-12 11:29:46 +08:00
Joseph Huber
c02da3d903
[SPIR-V] Add clang builtin for subgroup shuffles (#174655)
Summary:
This is an attempt to begin filling out some missing pieces to allow
more generic compute code to use SPIR-V flavored builtins. This should
provide the basic shuffle operation. The next most important one is the
ballot, but I don't think we have an IR intrinsic for that yet.

I don't know SPIR-V very well so let me know if this is the proper
function with the proper semantic checks.
2026-01-08 15:55:50 -06:00
Maryam Moghadas
325869c7fc
[PowerPC] Add AMO load signed builtins (#168747)
This commit adds two Clang builtins for AMO load signed operations:

__builtin_amo_lwat_s for 32-bit signed operations
__builtin_amo_ldat_s for 64-bit signed operations
2026-01-08 11:59:54 -05:00
Shilei Tian
5a63367b15
Reapply "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674) (#174697)
This reverts commit 0b2f3cfb72a76fa90f3ec2a234caabe0d0712590.
2026-01-07 06:12:19 +00:00
dyung
0b2f3cfb72
Revert "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674)
Reverts llvm/llvm-project#174310

This change is causing 2 cross-project-test failures on
https://lab.llvm.org/buildbot/#/builders/174/builds/29695
2026-01-07 01:18:23 +00:00
Shilei Tian
ccca3b8c67
[AMDGPU] Rework the clamp support for WMMA instructions (#174310)
Fixes #166989.
2026-01-06 15:46:40 -05:00
Alex MacLean
b22bbe445f
[NVPTX][clang] Fixup support for bar0 reduction builtins (#173312) 2026-01-05 11:46:00 -08:00
Shilei Tian
c97de4387b
Revert "[AMDGPU] add clamp immediate operand to WMMA iu8 intrinsic (#171069)" (#174303)
This reverts commit 2c376ffeca490a5732e4fd6e98e5351fcf6d692a because it
breaks assembler.

```
$ llvm-mc -triple=amdgcn -mcpu=gfx1250 -show-encoding <<< "v_wmma_i32_16x16x64_iu8 v[16:23], v[0:7], v[8:15], v[16:23] matrix_b_reuse"
  v_wmma_i32_16x16x64_iu8 v[16:23], v[0:7], v[8:15], v[16:23] clamp ; encoding: [0x10,0x80,0x72,0xcc,0x00,0x11,0x42,0x1c]
```

We have a fundamental issue in the clamp support in VOP3P instructions,
which will need more changes.
2026-01-04 02:13:21 +00:00
Muhammad Abdul
2c376ffeca
[AMDGPU] add clamp immediate operand to WMMA iu8 intrinsic (#171069)
Fixes #166989 

- Adds a clamp immediate operand to the AMDGPU WMMA iu8 intrinsic and
threads it through LLVM IR, MIR lowering, Clang builtins/tests, and MLIR
ROCDL dialect so all layers agree on the new operand
- Updates AMDGPUWmmaIntrinsicModsAB so the clamp attribute is emitted,
teaches VOP3P encoding to accept the immediate, and adjusts Clang
codegen/builtin headers plus MLIR op definitions and tests to match
- Documents what the WMMA clamp operand do
- Implement bitcode AutoUpgrade for source compatibility on WMMA IU8
Intrinsic op

Possible future enhancements:
- infer clamping as an optimization fold based on the use context

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-12-27 12:51:29 -05:00
Gergo Stomfai
8290134a74
[X86] EmitX86BuiltinExpr - attempt to convert SSE41/AVX1 roundps/d/ss/sd builtins to regular rounding modes (#171227)
Adding clauses to `CodeGenFunction::EmitX86BuiltinExpr` to convert
SSE4.1/AVX1 builts `roundps/pd/ss/sd` to regular rounding modes.

We use:
1. `roundeven/floor/ceil/trunc` when not using MXCSR or _MM_FROUND_RAISE_EXC , and FP mode is not strict,
2. `experimental_constrained_roundeven/floor/ceil/trunc` when not using MXCSR or _MM_FROUND_RAISE_EXC , and FP mode is strict
3. `x86_sse41/avx_round_ps/pd/ss/sd` when using MXCSR or _MM_FROUND_RAISE_EXC .

Closes #170273
2025-12-23 13:44:21 +00:00
Nikita Popov
3186ca25bc [ARM] Use getSigned() for signed value 2025-12-17 12:48:51 +01:00
Jim Lin
fcf762c6ec
[RISCV] Implement Clang Builtins for XAndesPerf Extension (#147018)
This patch adds the Clang builtins for byte comparision instructions in
XAndesPerf Extension. These instructions are hardly generated by
compiler. So we provide the Clang builtins for the user.

Please refer to:
https://github.com/andestech/andes-intrinsic-doc/blob/main/andes-scalar-intrinsic.md
2025-12-17 08:43:37 +00:00
David Green
1a1c5df7f9
[ARM] Introduce intrinsics for MVE fp-converts under strict-fp. (#170686)
This is the last of the generic instructions created from MVE
intrinsics. It was a little more awkward than the others due to it
taking a Type as one of the arguments. This creates a new function to
create the intrinsic we need.
2025-12-14 12:12:45 +00:00
Alexander Johnston
3142e3ab15
[HLSL] Implement ddx and ddy HLSL intrinsics (#168887)
Implements the ddx and ddy HLSL intrinsics. The DXIL intrinsics call the
ddx_coarse and ddy_builtins as they lower to the coarse variants.
The SPIRV intrinsics lower to their own opcodes OpDPdx and OpDPdy. Tests
are added to ensure the SPIRV builtins are not available outside of
shaders stage.

Closes https://github.com/llvm/llvm-project/issues/99096
Closes https://github.com/llvm/llvm-project/issues/99099
2025-12-11 10:04:35 -08:00
Amina Chabane
7f2e6f128d
[Clang][AArch64] Implement widening FMMLA intrinsics (#165282)
Proposed in [this ACLE
proposal](https://github.com/ARM-software/acle/pull/409), this PR
implements widening FMMLA intrinsics.

- F16 to F32
- MF8 to F32
- MF8 to F16

Additional changes:
- IsOverloadCvt flag renamed to IsOverloadFirstandLast for clarity, as
the name implies conversion. Implementation remains unchanged.
2025-12-05 16:08:25 +00:00
Sven van Haastregt
98182f4d20
Move CodeGenFunction::EmitScalarOrConstFoldImmArg; NFC (#170286)
This function is called from various .cpp files under `TargetBuiltins/`,
and was moved unintentionally into `AMDGPU.cpp` in PR #132252. Move it
to a common place.
2025-12-03 08:58:31 +01:00
Simon Pilgrim
fca41f4aa1
[X86] Replace BF16 to F32 conversions with generic conversions (#169781)
Let standard casting / builtin_convertvector handle the conversions from BF16 to F32

My only query is how to best implement _mm_cvtpbh_ps - I went for the
v8bf16 -> v8f32 conversion followed by subvector extraction in the end,
but could just as easily extract a v4bf16 first - makes no difference to
final optimized codegen.

First part of #154911
2025-11-27 13:09:26 +00:00
Nikolas Klauser
0dbedd195c
[Clang] Replace some x86 sqrt builtins with the generic __builtin_elementwise_sqrt versions (#165682) 2025-11-27 11:36:43 +00:00
Aaditya
4604762cc3
[AMDGPU] Add builtins for wave reduction intrinsics (#161816) 2025-11-24 15:13:11 +05:30
Jordan Rupprecht
3d3307ecd8
[clang][NFC] Inline Frontend/FrontendDiagnostic.h -> Basic/DiagnosticFrontend.h (#162883)
d076608d58d1ec55016eb747a995511e3a3f72aa moved some deps around to avoid
cycles and left clang/Frontend/FrontendDiagnostic.h as a shim that
simply includes clang/Basic/DiagnosticFrontend.h. This PR inlines it so
that nothing in tree still includes clang/Frontend/FrontendDiagnostic.h.

Doing this will help prevent future layering issues. See #162865.

Frontend already depends on Basic, so no new deps need to be added
anywhere except for places that do strict dep checking.
2025-11-21 03:39:49 +00:00
Alexander Johnston
76f1949cfa
[HLSL] Implement the fwidth intrinsic for DXIL and SPIR-V target (#161378)
Adds the fwidth intrinsic for HLSL.
The DXIL path only requires modification to the hlsl headers.
The SPIRV path implements the OpFwidth builtin in Clang and instruction
selection for the OpFwidth instruction in LLVM.
Also adds shader stage tests to the ddx_coarse and ddy_coarse
instructions used by fwidth.

Closes #99120

---------

Co-authored-by: Alexander Johnston <alexander.johnston@amd.com>
2025-11-20 07:38:32 -05:00
Simon Pilgrim
59c01cc8bb
[Headers][X86] Update FMA3/FMA4 scalar intrinsics to use __builtin_elementwise_fma and support constexpr (#154731)
Now that #152455 is done, we can make all the scalar fma intrinsics to
wrap __builtin_elementwise_fma, which also allows constexpr

The main difference is that FMA4 intrinsics guarantee that the upper
elements are zero, while FMA3 passes through the destination register
elements like older scalar instructions

Fixes #154555
2025-11-13 11:36:22 +00:00
Jonathan Thackray
7377ac037d
[AArch64][llvm] Add support for Neon vmmlaq_{f16,f32}_mf8_fpm intrinsics (#165431)
Add support for the following new AArch64 Neon intrinsics:
```
float16x8_t vmmlaq_f16_mf8_fpm(float16x8_t, mfloat8x16_t, mfloat8x16_t, fpm_t);
float32x4_t vmmlaq_f32_mf8_fpm(float32x4_t, mfloat8x16_t, mfloat8x16_t, fpm_t);
```
2025-11-07 15:24:13 +00:00
Jonathan Thackray
9a8781b86f
[AArch64][llvm] Add support for new vcvt* intrinsics (#163572)
Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```
2025-11-07 14:56:29 +00:00
Alex MacLean
4a383f9ff7
[NVPTX] Add ex2.approx bf16 support and cleanup intrinsic definition (#165446) 2025-11-01 17:51:17 +00:00
Mikołaj Piróg
5322fb6268
[X86] Remove AMX-TRANSPOSE (#165556)
Per Intel Architecture Instruction Set Extensions Programming Reference
rev. 59 (https://cdrdv2.intel.com/v1/dl/getContent/671368), Revision
History entry for revision -59, AMX-TRANSPOSE was removed
2025-10-31 12:50:21 +01:00
Rana Pratap Reddy
24c75a21b8
[AMDGPU][Clang] Support for type inferring extended image builtins for AMDGPU (#164358)
Introduces the builtins for extended image insts for amdgcn.
2025-10-30 22:20:28 +05:30
Paul Walker
d929146b3f
[Clang][AArch64] Lower NEON vaddv/vminv/vmaxv builtins to llvm.vector.reduce intrinsics. (#165400)
This is the first step in removing some NEON reduction intrinsics that
duplicate the behaviour of their llvm.vector.reduce counterpart.

NOTE: The i8/i16 variants differ in that the NEON versions return an i32
result. However, this looks more about making their code generation
convenient with SelectionDAG disgarding the extra bits. This is only
relevant for the next phase because the Clang usage always truncate
their result, making llvm.vector.reduce a drop in replacement.
2025-10-30 10:46:37 +00:00
Brandon Wu
fb87708317
[RISCV] Support XSfmm C intrinsics (#143070)
In this version of intrinsics, users need to manage the life time of
tiles on their own, compiler doesn't have tile type for variables not
only for design simplicity but also preventing users to write bad
performance code that could potentially having tile spills which are
quite expensive in terms of cycles.

Intrinsics are specified at the end of this document
https://www.sifive.com/document-file/xsfmm-matrix-extensions-specification

stack on: https://github.com/llvm/llvm-project/pull/143068 and
https://github.com/llvm/llvm-project/pull/143069
2025-10-25 02:38:43 +08:00
macurtis-amd
5440cfc450
[clang] Add support for cluster sync scope (#162575)
From Sam Liu:
>CUDA supports thread block clusters
https://docs.nvidia.com/cuda/cuda-c-programming-guide/#thread-block-clusters
>
>In their atomic intrinsics, cluster scope is supported
https://docs.nvidia.com/cuda/cuda-c-programming-guide/#nv-atomic-fetch-add-and-nv-atomic-add
>
>For compatibility, clang and hip needs to support cluster scope.
2025-10-21 05:47:26 -05:00
Juan Manuel Martinez Caamaño
74d77dc2ec
[Clang][NFC] Rename UnqualPtrTy to DefaultPtrTy (#163207)
`UnqualPtrTy` didn't always match `llvm::PointerType::getUnqual`:
sometimes it returned a pointer that is not in address space 0 (notably
for SPIRV).

Since `UnqualPtrTy` was used as the "generic" or "default" pointer type,
this patch renames it to `DefaultPtrTy` to avoid confusion with LLVM's
`PointerType::getUnqual`.
2025-10-20 14:34:21 +02:00
Kazu Hirata
4412cfa854
[clang] Use [[fallthrough]] instead of LLVM_FALLTHROUGH (NFC) (#163085)
[[fallthrough]] is now part of C++17, so we don't need to use
LLVM_FALLTHROUGH.
2025-10-12 20:49:11 -07:00
Rana Pratap Reddy
f2ffb4d20b
[AMDGPU] Support for type inferring image load/store builtins for AMDGPU (#140210)
Introduces the builtins for amdgcn_image_load/store/sample.
2025-10-10 15:26:08 +05:30
Maryam Moghadas
ff14953128
[Clang][PowerPC] Add __dmr2048 type and DMF crypto builtins (#157152)
Define the __dmr2048 type to represent the DMR pair introduced by the
Dense Math Facility on PowerPC, and add three Clang builtins
corresponding to DMF cryptography:

__builtin_mma_dmsha2hash
__builtin_mma_dmsha3hash
__builtin_mma_dmxxshapad

The __dmr2048 type is required for the dmsha3hash crypto builtin, and,
as withother PPC MMA and DMR types, its use is strongly restricted.
2025-09-30 09:16:43 -04:00
Alex Voicu
d481e5f9b7
[AMDGPU][SPIRV] Use SPIR-V syncscopes for some AMDGCN BIs (#154867)
AMDGCN flavoured SPIR-V allows AMDGCN specific builtins, including those
for scoped fences and some specific RMWs. However, at present we don't
map syncscopes to their SPIR-V equivalents, but rather use the AMDGCN
ones. This ends up pessimising the resulting code as system scope is
used instead of device (agent) or subgroup (wavefront), so we correct
the behaviour, to ensure that we do the right thing during reverse
translation.
2025-09-29 22:50:15 +01:00
Simon Pilgrim
5169bb4c81
[clang][x86] Change SLLDQ/SRLDQ byte shift intrinsics to use vXi8 types instead of vXi64 (#158671)
As noted on #156494 and #157403 - its much easier to work with the byte
shift intrinsics if we treat them as vXi8 types instead of vXi64 types
which will require bitcasting

We already do this for the PALIGNR intrinsics which are a more advanced
version of the same shuffle
2025-09-16 07:53:59 +00:00
Kerry McLaughlin
ccaeebcd04
[AArch64][SME] Improve codegen for aarch64.sme.cnts* when not in streaming mode (#154761)
Builtins for reading the streaming vector length are canonicalised to
use the aarch64.sme.cntsd intrinisic and a multiply, i.e.
  - cntsb -> cntsd * 8
  - cntsh -> cntsd * 4
  - cntsw -> cntsd * 2

This patch also removes the LLVM intrinsics for cnts[b,h,w], and adds
patterns to improve codegen when cntsd is multiplied by a constant.
2025-09-12 10:23:57 +01:00
Aaditya
924bf242c8
[AMDGPU] Add builtins for wave reduction intrinsics (#150170) 2025-09-10 19:06:07 +05:30
Pierre van Houtryve
e2bd10cf16
[AMDGPU][gfx1250] Add 128B cooperative atomics (#156418)
- Add clang built-ins + sema/codegen
- Add IR Intrinsic + verifier
- Add DAG/GlobalISel codegen for the intrinsics
- Add lowering in SIMemoryLegalizer using a MMO flag.
2025-09-04 09:19:25 +00:00