<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64004>64004</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization: when the value of another variable can be used directly
</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>
Test code: https://godbolt.org/z/e97jKPr7e
```C++
int var22=0;
int var23=0;
void test(int var7, int var9, int var11, int var12) {
var22 = var12 + var9 + var11;
var23 = var12 + (var9 + var7 + var11);
}
```
IR at -O3
```
%add = add i32 %var11, %var9
%add1 = add i32 %add, %var12
store i32 %add1, ptr @var22, align 4
%add3 = add i32 %add, %var7
%add4 = add i32 %add3, %var12
store i32 %add4, ptr @var23, align 4
ret void
```
In fact, `var23` can be directly optimized to `var22+var7`, but LLVM does not do this in the IR generated at the O3 optimization level.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN9r4zAM_muUF7HiyPnRPORhXSmM29gxjoO7N6dWGw83LrHTsf31h5N2a3vjODBYlr9PnyRHUd6bbcdcQ76AfJmoIbSur3__yrMiaZx-q3-wD7h2mkHeYhvC3oO8BVoBrbZON86Gmeu3QKt3oBVX5cu3733JIJYgbqEQ07oDWsQ1ek0X8KB6IpBLAfLKKy-8B2c0BvYBaH5ElEB3eLSrMztNzw8EVCGUxzCTHoJcTpcItBj5JyNNPyQRcUrkCg40P2eUZ1SqPthQLq9qn473z6gC3jzJL28RgXKl9SgZdyOjaP5R1mRXR_QETq_RSutPbEqn0D64ns8wY8B96BEyMb0D3aGyZtthdiEg_ylQXqaefQGW_5NOdpWO_Dsd7Dlg_BS-bm2HG7UOo1ZxDFEIXKsOG0Ztel4H-4ZuH8zOvLPG4E5AAlqMpRQi0psh4MPDz0fUjj12LqB2GFrj0XQYWsb7Z9xyx70KrON7Rt-TPIVWwbgOLR_YzhJdS13JSiVcp8W8qmRWzilpa51JvSnzzbohpZVQKtdN0aTlvChSRZQmpiZBUpSUpiKtMppxqXW6zqXYaCrTeQWZ4J0ydmbtYReHLzHeD1wXmRBZYlXD1o_zTNTxK46XQBTHu68j56YZth4yYY0P_jNKMMFy_Wi8Z31RUpz815anFhyUHRjdBlXnQst9HAGjGsunhg-Rfup6MvS2vvprmNAOzWztdkCrKH7cbva9e-H4jqsxZQ-0Gkv6EwAA__8e5FV8">