[all-commits] [llvm/llvm-project] 6c3604: [NVPTX] Add support for f32x2 mixed-precision add/...

Srinivasa Ravi via All-commits all-commits at lists.llvm.org
Thu Sep 17 02:31:02 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6c3604b43ca23b305c10b60ed9120ea56f872233
      https://github.com/llvm/llvm-project/commit/6c3604b43ca23b305c10b60ed9120ea56f872233
  Author: Srinivasa Ravi <srinivasar at nvidia.com>
  Date:   2026-09-17 (Thu, 17 Sep 2026)

  Changed paths:
    M llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
    M llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
    A llvm/test/CodeGen/NVPTX/mixed-precision-add-f32x2-downconvert-invalid.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-add-f32x2-downconvert.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-add-f32x2-upconvert-invalid.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-add-f32x2-upconvert.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-f32x2-sm-version.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-sub-f32x2-downconvert-invalid.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-sub-f32x2-downconvert.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-sub-f32x2-upconvert-invalid.ll
    A llvm/test/CodeGen/NVPTX/mixed-precision-sub-f32x2-upconvert.ll

  Log Message:
  -----------
  [NVPTX] Add support for f32x2 mixed-precision add/sub (#221957)

This change adds support for mixed precision addition and 
subtraction of `f16x2` and `bf16x2` with `f32x2`, where the
following upconverting patterns:
```
%e = fpext <2 x half> %h to <2 x float>
%res = fp-operation(%e, ...)
...
%e = fpext <2 x bfloat> %b to <2 x float>
%res = fp-operation(%e, ...)

where the fp-operation can be any of:
- fadd
- fsub
- llvm.nvvm.fadd.v2f32
```
are lowered to `add/sub.{rnd}.f32x2.{f16x2/bf16x2}.f32x2`, and the
following downconverting pattern:
```
%sum = llvm.nvvm.fadd{.ftz}.v2f32(%a, %b, rz)
%lo = extractelement <2 x float> %sum, i32 0
%hi = extractelement <2 x float> %sum, i32 1
%res = llvm.nvvm.ff2{f16x2/bf16x2}.rz(%hi, %lo, false)
```
is lowered to `add/sub.rz{.ftz}.{f16x2/bf16x2}.f32x2.f32x2`. These
instructions combine the conversion and the addition into one
instruction from `sm_107f` onwards. `fneg` followed by one of the
above addition patterns is lowered to the corresponding `sub`
instruction.

The upconverting patterns are folded only when atleast one of the
`fpext`
operands have a single use, thus purely eliminating the conversion.
The downconverting patterns are folded only when the `f32x2` result
is used solely by the conversion, avoiding generating an unnecessary
additional `add/sub` instruction.

The tests have been verified through ptxas-13.4.

PTX spec reference:
https://docs.nvidia.com/cuda/developer-preview/13.4/parallel-thread-execution/index.html#mixed-precision-floating-point-instructions-add



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list