<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57654>57654</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Reassociate replaces shl+or+sub with mul+sub+add
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue,
llvm:optimizations
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chfast
</td>
</tr>
</table>
<pre>
The `opt -reassociate -instcombine` changes
```llvm
define i64 @sub4(i64 %x, i32 %y0, i64 %d) local_unnamed_addr {
%e = shl i64 %d, 32
%f = zext i32 %y0 to i64
%y = or i64 %e, %f
%s = sub i64 %x, %y
ret i64 %s
}
```
to
```llvm
define i64 @sub4(i64 %x, i32 %y0, i64 %d) local_unnamed_addr {
%e.neg1 = mul i64 %d, -4294967296
%f = zext i32 %y0 to i64
%y.neg = sub i64 %x, %f
%s = add i64 %y.neg, %e.neg1
ret i64 %s
}
```
https://godbolt.org/z/YWGP5Tj3W
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFU8GOmzAQ_RpzsRKRMYZw4JBslF6raqVVTyuDB_DK4Aib7iZfX9tstHSrHtpLJWM8zJvnNw-7NvJaPfZISZ6ai6ObCYW1plHCId2o0brGDLUa0edp04uxQ0vSE0kP73OeLkPrH8PySWLr8VTlGSVZauc6I7CPEfA3Ag9UMQjraxqDJSEJlFSbRujneRzFgPJZSDlRUhwXVhpQXiY7UdvrVdkDZbCCtBFywzf3sQ91JhSsUNeIMtOdBwNPqF5h7LLZXNO1-FB8B03o7rm7KcXpky9rs5z5j9ZtR-x2saVh_tW_TQZlVuYFlPnfGxlo_2TU7256YXdQrHwHLuL-1dbeuYsl7EDg7EdnZG2025rJs59v_vn-9OUrf3xhTwlWuzyHghWMQSIrJktWisQpp7H6tjr4E160aNCGo0bgaCY_hf5eleuDfUvoZ99PMk-6-iTBw-Z662-OD-LfXV6by2ResHE-VNbO_ibBmRc5z5K-wlwyaEu-w0KwrIZ0V4pWNrLmRZu1NU-0qFHbivAjARjxlUYKv148hLgPO_hLrAZ1E06Z0YYsPyWqghQgLdNyx2HPYSsEikZmTbvn-6yR0h82HITS20ASnEumKgqu5876pFbW2Y-kN0p1I2IU4_nF7HozVU3fCuuSqKuKff0EvnE2ZA">