<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58458>58458</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86] wrong code for inline asm with multiple flag outputs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lhmouse
</td>
</tr>
</table>
<pre>
Godbolt: <https://gcc.godbolt.org/z/jbWrvW5c9>
```c
int
get_cc(void* ptr)
{
int nzf, cf;
__asm__ ("nop" : "=@ccnz"(nzf), "=@ccc"(cf) : "r"(ptr));
return nzf | -cf;
}
```
Clang 14 gives:
```asm
get_cc: # @get_cc
xor ecx, ecx
nop
setne cl
sbb eax, eax
or eax, ecx
ret
```
but Clang 15 gives:
```asm
get_cc: # @get_cc
xor ecx, ecx
nop
setne cl
xor eax, eax # <---------- This clobbers CF
sbb eax, eax
or eax, ecx
ret
```
which contains a redundant `xor eax, eax` instruction that invalidates CF output from inline assembly, and is wrong code, of course.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVE1v4yAQ_TX4ghrZELv2wYc22e4fWKnHCAO2qTBEfCRtf_0OdupNolWPKy3CBuYxM28eNp0VH-1PKzqrA6JPGNHdGMLRwxyRF-gD55thwTfWDWD5hOete3Wn15I3iP5A-R7lT5d3lS-dL2tlwjIZZDhwjkh9skog8oSPwSHSLCDG6PH5a4oxOGHz2SOyw7xH9Ao5HJifDgcMcRAhxh7hjWfahCC6R9ucc_OZFqSeIzQpyBXIF4wn6MvRLbYLIejXGZ0M0ZlEBzju8MMNIfS4vyv7WoudZmbAxRYP6iRnQf8mFBR0oxCd037bEKEYqrk4rFRTe7duHiV_T5Wn4QZPkt0YvAxGwsj1nb3rlkBsCcTuAl3yrPh9ItDtG2m6GPBFnvK_lGcNtMqzZqa7h7XhX6Py4Gy7TjqPdy__UuTzqPiIuTWBKeMxg-0iGsHg74KdqYKrvFUOv50PLvKgrMFhZAEMJ6aVYEEm6tjGcIRz652dANIKhGHey6nTHykKMwJDsWdn4Vi5FTIZbQ_T6LzcLJwy2RZVVRVlRXKSiZaKhjYsCypo2aLy-b2uULm_CoJ74Llmm_BZhRFPUQd11ABqNlx4-Sw63d7dXbA5dhtuJ1hoffoaHo7OvkkeYKm8j_D1kZey3pZ1NrZlXtBS8IayIi94XpSF6AvGJK1lIQraZ5p1UvtENl1B8oznEOkOKfeZaqEuAp5NXhZ5TjasKR5rInnVEC62WwYfppyY0pvEI12omWtnSl0cPIBa-eD_gCCwGoyctUnxWQyjBY9xstHLbE7dztR_A4ABkdg">