<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58465>58465</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Unable to lower `fadd` when arguments are `bfloat`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          banach-space
      </td>
    </tr>
</table>

<pre>
    I came across this LLVM IR that the AArch64 backend refuses to lower ATM:

```llvm
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
define bfloat @kernel_sum_reduce(bfloat %0, bfloat %1) {
  %3 = fadd bfloat %0, %1
  ret bfloat %3
}
```

To reproduce (skipping the triple as testing on an AArch64 host):
```bash
$ llc --mattr=+bf16 bfloat_add.ll
LLVM ERROR: Cannot select: t5: bf16 = fadd t2, t4
  t2: bf16,ch = CopyFromReg t0, Register:bf16 %0
    t1: bf16 = Register %0
  t4: bf16,ch = CopyFromReg t0, Register:bf16 %1
    t3: bf16 = Register %1
```
Tested using ToT: [82c820b95cf7](https://github.com/llvm/llvm-project/commit/82c820b95cf7ec284baf182cf838ca9e26758098). This is not a problem for the X86 backend. I haven't checked other backends.

**Short analysis**

There is no `fadd` for `bfloat`s (aka `bf16`) on AArch64: [A64 -- SIMD and Floating-point Instructions](https://developer.arm.com/documentation/ddi0602/2022-09/SIMD-FP-Instructions). The backend could choose to transform `bfloat`s to `float`s, but currently it does not.

IIUC, Clang wouldn't produce this code to begin with. I have extracted it from MLIR's [sparse_sum_bf16.mlir](https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_sum_bf16.mlir) (CC @d0k ), which is failing for me on AArch64 (and this looks like the root cause).

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVVtv6jgQ_jXwYoFyJ3nggcIiIbXaIw492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