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

    <tr>
        <th>Summary</th>
        <td>
            [x86-64] Assembly Issue on Intel AMX instruction
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          witbring
      </td>
    </tr>
</table>

<pre>
    I found that Clang allows some AMX (Advanced Matrix Extension) instructions that GAS disallows. 
Specifically, GAS enforces tdpbf16ps, tdpbssd, tdpbusd, tdpbsud, tdpduud, and tdpfp16ps to have distinct registers, whereas Clang permits them to have non-distinct registers. 
Additionally, when using the GAS disassembler (objdump), it prints the binary code with a 'bad' alarm.

Here is an example code snippet:
```asm
.intel_syntax noprefix
    tdpbf16ps TMM0, TMM0, TMM0
    tdpbssd TMM0, TMM0, TMM0
    tdpbusd TMM0, TMM0, TMM0
 tdpbsud TMM0, TMM0, TMM0
    tdpbuud TMM0, TMM0, TMM0
    tdpfp16ps TMM0, TMM0, TMM0
```

Clang successfully assembles these instructions. The disassembly of the Clang-compiled code is shown below:
```bash
 tdpbf16ps tmm0/(bad),tmm0/(bad),tmm0/(bad)
 tdpbssd tmm0/(bad),tmm0/(bad),tmm0/(bad)
 tdpbusd tmm0/(bad),tmm0/(bad),tmm0/(bad)
 tdpbsud tmm0/(bad),tmm0/(bad),tmm0/(bad)
 tdpbuud tmm0/(bad),tmm0/(bad),tmm0/(bad)
 tdpfp16ps tmm0/(bad),tmm0/(bad),tmm0/(bad)
```

In contrast, GAS emits error messages for the same code:
```bash
<source>: Assembler messages:
<source>: Warning: end of file not at end of a line; newline inserted
<source>:2: Error: all tmm registers must be distinct for `tdpbf16ps'
<source>:3: Error: all tmm registers must be distinct for `tdpbssd'
<source>:4: Error: all tmm registers must be distinct for `tdpbusd'
<source>:5: Error: all tmm registers must be distinct for `tdpbsud'
<source>:6: Error: all tmm registers must be distinct for `tdpbuud'
<source>:7: Error: all tmm registers must be distinct for `tdpfp16ps'
Compiler returned: 1
```

You can reproduce these result on godbolt:
https://godbolt.org/z/n99Tf3vdj
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslktv4zYQgH8NfRnEkCnLtg46eJO4zSGnDdD2VFDiSGJAkQKH9KO_vqDkV3aTIFgvEERjaebjvDikIFKNQSxY9o1lDxMRfGtdsVO-dMo0k9LKQ_EEtQ1Ggm-Fh3stTANCa7sjINshrJ__BsZXa7kVpkIJz8I7tYfHvUdDyhrGc1CGvAuVV9bQyPlj_R2kohE0BZY8sGT9vcdK1aoSWh8Yvx-U0NTWVUjgZV_Ws0VP8Uv8QSRPYriIFE6iDKMoou-yr_toDN5CK7YYF_fKVB4cNoo8uoG7a9GhoGOYPbpO-egxdmdDY83dz8anENZSqhjmKYRdiwYCKdNEyjlsIuxKjS5mzpavMnQ943k0UB56p8y4KpTKCHeAykqEnfItCGB8WQrJ-BKEFq6bjuuO__9Eh6AIhAHci67XOJqSUX2PnqVHPbZIxj9B3fhmqoxH_S8djBd7MLZ3WKv9-A0ALtmHl-fnJDr65vlGj0h-QSt8rnWs5VdAX9E6Vv9jvXNKrvM5tgGFqkKiOmh9gFPphvoQvmntKby0eFXfA9h6KOPAuats1yuNcqyJIqDW7gyUqO3u59KUgtqrXIzJ912XML5hfDX0QOyYr7y6SinJ2yHhd0BicW_35DdAToPhBsy7zfNkoLLGO0H-PMyGcYLOWQcdEokGCWrrhiYh0Y3b9bNeYOk92eAqZOkjS9ewPk-SE-9i_YPqX8IZZZooopGxNWul4zzzIPzplQCtDLL0GxjcRTE2ODqP8l0oj7THGE8UhNYxjZepCF0gD-XVtI3BskVyNcyX74LTG8DDwfA-dn4DNnyMzW7xNnyIXdzi7cfY5a9jx71yBt-PE82BQx-cQRmBs0_2xD82QCUMOOydlaHC4xR1SEF7sAYaK0urL0dV630_9HTcdJvj16l1DeO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