<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78438>78438</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: (1/(y+1))/2 => 0
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ZY546
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/exPx5Th8G
```cpp
void func(int x, int y){
a=2;
b=2;
c=(1/(y+1))/a;
}
```
Clang -O3:
```asm
func(int, int): # @func(int, int)
mov dword ptr [rip + a], 2
mov dword ptr [rip + b], 2
lea ecx, [rsi + 2]
xor eax, eax
cmp ecx, 2
ja .LBB0_2
inc esi
mov eax, esi
shr eax, 31
add eax, esi
sar eax
.LBB0_2: # %select.end
mov dword ptr [rip + c], eax
ret
```
But the code below works as expected:
```cpp
void func2(int x, int y){
a=2;
//b=2;
c=(1/(y+1))/a;
}
```
Clang -O3:
```asm
func2(int, int): # @func2(int, int)
mov dword ptr [rip + a], 2
mov dword ptr [rip + c], 0
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VUFzmzoQ_jXLRROPWIHBBw4hfrzLe9MeemkvHSEpRqlADBKxk1_fEThObNNmcmg1jOXZ3U_7sbuf4M7pXadUAWkJ6Tbio2_sUHz7mibrqLbyqWi87x2wW8AKsNpZWVvjV3bYAVbPgJU6fD6kX5r8X6BboLfH3zWdH9H3s-XRaknux04A5rrz5AB4R8KfJ8ANZOUcRQghHNgWgb2x1OcWAWwLmMcTo_wJsIzDGeGp-CkMsu0Fl7cE7wzvduTmEwtvdh7GXTtbXtkeuYYU7JYAMgIJXXSfOIfV2sdpl3s7SNL7gUBaDrongCXhkG4DED-AqZcxRvFpV2KqagA4PQEwAM5iD3aYY_kUG7Yzv2j7t2ddZHrgZPVfWdLvF3bdiRnl9PLrvKQ7-V1zxoPF5zgu5TLuuBwfXrm_UGIn96_W1DpMnTJK-JXq5DXbxcKLY-GvyjUo_5spK0dPfKOIsFKRWhm7J3s7_HCEO6IOvRJeyesBvNYMflQ0s1jrKyX9Tengknbebc6sq2vsnxXWS3_pe92NZMHkhm14pIo4o2mySRnmUVNIGVMuUpFksUzUWuQ5ru8zfl_XtZI1TSNdIMWExnEWY4I0XyUsWW9ymbEEY6owhYSqlmuzMuaxDRdspJ0bVZHlCcsjw2tl3HRNI3ZqTyYnYFB4NBQBc1OPOwcJNdp593qK196o4n_tnJLE9l63-pl7bbv5LlseBiRhUtg_hEbjYC4_Ato3Y70StgWsQp7jdtMP9kEJD1hN7BxgNbH_GQAA__-Zw6Lk">