<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88501>88501</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86] Backend Bugs
</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>
Hello, we've identified a bug during our research and would like to report it. It appears that the following assembly code is being incorrectly assembled by clang (32-bit). Could you please investigate this? Thank you.
Assembly code (bug.s)
```
.intel_syntax noprefix
cmpbxadd DWORD PTR [1], EDI, EBP
cmplexadd DWORD PTR [1], EDI, EBP
cmplxadd DWORD PTR [1], EDI, EBP
cmpnbexadd DWORD PTR [1], EDI, EBP
cmpnbxadd DWORD PTR [1], EDI, EBP
cmpbexadd DWORD PTR [1], EDI, EBP
cmpnlxadd DWORD PTR [1], EDI, EBP
cmpnoxadd DWORD PTR [1], EDI, EBP
cmpnpxadd DWORD PTR [1], EDI, EBP
cmpnsxadd DWORD PTR [1], EDI, EBP
cmpnzxadd DWORD PTR [1], EDI, EBP
cmpoxadd DWORD PTR [1], EDI, EBP
cmppxadd DWORD PTR [1], EDI, EBP
cmpbexadd DWORD PTR [1], EDI, EBP
cmpsxadd DWORD PTR [1], EDI, EBP
cmpzxadd DWORD PTR [1], EDI, EBP
```
When I compile above code with x86 option, then clang assembler (v16.0.0) generates weird binary code as follows.
```
$ bin/clang -m32 -c bug.s -o bug_x86.o
$ bin/objdump -d bug_x86.o
bug_x86.o: file format elf32-i386
Disassembly of section .text:
00000000 <.text>:
0: c4 e2 51 e2 (bad)
4: 3d 01 00 00 00 cmp eax,0x1
9: c4 e2 51 ee (bad)
d: 3d 01 00 00 00 cmp eax,0x1
12: c4 e2 51 ec (bad)
16: 3d 01 00 00 00 cmp eax,0x1
1b: c4 e2 51 e7 (bad)
1f: 3d 01 00 00 00 cmp eax,0x1
24: c4 e2 51 e3 (bad)
28: 3d 01 00 00 00 cmp eax,0x1
2d: c4 e2 51 e6 (bad)
31: 3d 01 00 00 00 cmp eax,0x1
36: c4 e2 51 ed (bad)
3a: 3d 01 00 00 00 cmp eax,0x1
3f: c4 e2 51 e1 (bad)
43: 3d 01 00 00 00 cmp eax,0x1
48: c4 e2 51 eb (bad)
4c: 3d 01 00 00 00 cmp eax,0x1
51: c4 e2 51 e9 (bad)
55: 3d 01 00 00 00 cmp eax,0x1
5a: c4 e2 51 e5 (bad)
5e: 3d 01 00 00 00 cmp eax,0x1
63: c4 e2 51 e0 (bad)
67: 3d 01 00 00 00 cmp eax,0x1
6c: c4 e2 51 ea (bad)
70: 3d 01 00 00 00 cmp eax,0x1
75: c4 e2 51 e6 (bad)
79: 3d 01 00 00 00 cmp eax,0x1
7e: c4 e2 51 e8 (bad)
82: 3d 01 00 00 00 cmp eax,0x1
87: c4 e2 51 e4 (bad)
8b: 3d 01 00 00 00 cmp eax,0x1
```
Fortunately, it seems to function correctly when compiled with the x64 option.
```
$ bin/clang -c bug.s -o bin_x64.o
$ bin/objdump -d bin_x64.o
bin_x64.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: c4 e2 51 e2 3c 25 01 cmpbxadd DWORD PTR ds:0x1,edi,ebp
7: 00 00 00
a: c4 e2 51 ee 3c 25 01 cmplexadd DWORD PTR ds:0x1,edi,ebp
11: 00 00 00
14: c4 e2 51 ec 3c 25 01 cmplxadd DWORD PTR ds:0x1,edi,ebp
1b: 00 00 00
1e: c4 e2 51 e7 3c 25 01 cmpnbexadd DWORD PTR ds:0x1,edi,ebp
25: 00 00 00
28: c4 e2 51 e3 3c 25 01 cmpnbxadd DWORD PTR ds:0x1,edi,ebp
2f: 00 00 00
32: c4 e2 51 e6 3c 25 01 cmpbexadd DWORD PTR ds:0x1,edi,ebp
39: 00 00 00
3c: c4 e2 51 ed 3c 25 01 cmpnlxadd DWORD PTR ds:0x1,edi,ebp
43: 00 00 00
46: c4 e2 51 e1 3c 25 01 cmpnoxadd DWORD PTR ds:0x1,edi,ebp
4d: 00 00 00
50: c4 e2 51 eb 3c 25 01 cmpnpxadd DWORD PTR ds:0x1,edi,ebp
57: 00 00 00
5a: c4 e2 51 e9 3c 25 01 cmpnsxadd DWORD PTR ds:0x1,edi,ebp
61: 00 00 00
64: c4 e2 51 e5 3c 25 01 cmpnzxadd DWORD PTR ds:0x1,edi,ebp
6b: 00 00 00
6e: c4 e2 51 e0 3c 25 01 cmpoxadd DWORD PTR ds:0x1,edi,ebp
75: 00 00 00
78: c4 e2 51 ea 3c 25 01 cmppxadd DWORD PTR ds:0x1,edi,ebp
7f: 00 00 00
82: c4 e2 51 e6 3c 25 01 cmpbexadd DWORD PTR ds:0x1,edi,ebp
89: 00 00 00
8c: c4 e2 51 e8 3c 25 01 cmpsxadd DWORD PTR ds:0x1,edi,ebp
93: 00 00 00
96: c4 e2 51 e4 3c 25 01 cmpzxadd DWORD PTR ds:0x1,edi,ebp
9d: 00 00 00
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysmN-P2jgQx_8a8zIicpzfDzzsLkXXp6uqSn2sHHsCbkMcxc7C3l9_CrB0a2fTJncIBQgz82Ey-c7YcGPUvkHckOSRJNsV7-1Bd5uTsmWnmv2q1PJl8xfWtSbsCU5IWPaMoCQ2VlUKJXAo-z3IfrAG3XfQoUHeiQPwRsJJ97WEWv1AsBo6bHVnQdkAPlrgbYu8M2AP3II9IFS6rvVpiMONwWNZv4DQEkEZKHE4rRqhuw6FrV9eTVBC-QKi5s0eCMsjti6VJawI4OmCftE9tDVyg6CaZzRW7blFsAdlSLSDLwfe_BiMAkK3hD5cjw-_4AnLy34fGMKKm1FKb8_Lx0A1Futv5qWx_AyNbjus1Pn6HQCAOLblmUsJ269_f97Cpy-fgSSPIUm2wyX9sP14eXn8BCOPX6LU-Cdhbi6D_QzzK6Ep5yBefWa7LKEsSEbPd2nnu5j5Lv_MdpmfypxMlpVkTuLi2M5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