<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58457>58457</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[x86] Conditional stack frame uses add rsp instead of pop on minsize
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
easyaspi314
</td>
</tr>
</table>
<pre>
When a stack frame is delayed to a conditional branch, the `X86FrameLowering::adjustStackWithPops()` optimization is not used on `-Oz`.
https://godbolt.org/z/f84EGcc8o
```c
void side_effect(void);
int foo(int b)
{
if (b) side_effect();
return 1;
}
```
`clang-15 --target=x86_64-linux-gnu -masm=intel -Oz`
```asm
foo: # @foo
test edi, edi
je .LBB0_2
push rax
call side_effect@PLT
add rsp, 8
.LBB0_2:
push 1
pop rax
ret
```
Expected:
```asm
foo: # @foo
test edi, edi
je .LBB0_2
push rax
call side_effect@PLT
pop rdx
.LBB0_2:
push 1
pop rax
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVMGOmzAQ_Rq4WERgA4EDh81m00ukrtRK29vK4AG8NRhhs03y9R3DbppEkXrqpZbxMPPGM4-xmVKLY_HSQk84MZZXP0k98g6INESA4kcQxGrEKt0LaaXuuSLlyPuq9egjsS0QLw1_ZOnO7drrXzDKvvHYA04u3iZjv7mgL9K2z3owHs08muMOogcrO3niLqRL1mtLJoPZUEU8-HrCdUWIF2698GFZW2sxBMamO5yNFqVWdqXHBrUTPnUWP32pqkx_bErDZVaL_q6lIEYKeIW6hsoiGWdyhNhmcZG9JbXWiLi30kFLqPWHA8Eha4IODryJdhnJOY5gp7En0dnorbc31M5qpXjfBFFCgsDysQHrse0hS1_TOFCynw5B008k6LjpEEByoMhSo5uAzmG2uM9gM42_DY8y4sWh23Cm7oYFY50EId1ZO3GFv8EiV_vNJnyl1-AwmXauAT9cAxVXysnL0sXh8_77tRsXYpajGVzybEE_U7GH-9miG7MeyF0SeDL3D2Jenw4DsgJxTvPfVfdcGHH414X1oYjSNI0SltHEFwUTOcu5b6VVUHjJBi-5l2zJ40V_uexD2BPMfBnwIhDZGwsce0Q9M8BW0aFJnsCfRlXctAdsOVO5qnSHilLvnyIYRv02_687acwE2JN2SRYna78tuEjyuoxSXvMsKmkClPF1XiV5wuJS5LmveAnKONrI2ZcFDSmNwigPYxbSZMVLtmZ5zgSEZVJThqWHjku1coldo_LHYuZQTo1BUEljzR-QGyObHuAzPp9sq8cCuDlyM0gWxf5MuZj5_gYWd43Y">