<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64012>64012</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Redundant code after optimization (Clang10 vs Clang16)
</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/64aG9xz6e
```C++
int var_19,var_30;
void test(int var_0, int var_1, int var_2, int var_3, int var_4) {
while(var_4){
if(var_0){
var_30 += var_1 + var_2;
}
else{
var_19+=200/(var_1+var_2);
}
var_4++;
}
}
```
IR generated by Clang10 -O1:
```
...
while.body.lr.ph: ; preds = %entry
%add = add nsw i32 %var_2, %var_1
br label %while.body
...
```
However, IR generated by Clang16 -O1 with obvious redundancy of `%add3`:
```
...
while.body.lr.ph: ; preds = %entry
%var_19.promoted = load i32, ptr @var_19, align 4
%var_30.promoted = load i32, ptr @var_30, align 4
%add = add nsw i32 %var_2, %var_1
%add3 = add nsw i32 %var_2, %var_1
br label %while.body
...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVM-P2joQ_msmF2sjZ5wf5JDDAuK9d3rSqpf2UjnxAK5MjGwDZf_6yiGBLUXa7loR8Xg8H998Mxnpvd70RA0UcyiWiTyErXXNt69FXiatVefmC_nAOqsIxDPbhrD3IJ4BV4CrjVWtNSG1bgO4egVclbn8p_75WhLwJfBnKPnlWQDO4zOc6j6wo3TfsxpwETeCgxh9R6sVC-QD4Gy6xwEX7Br01sC3hnhr5IA1g2pEZaetNgQ4m1w3z7j0evTyR964LkRZzEIsL1SiMfIQdxFQLX8_IOPphjulH7GQ80HO2ZjefMysfh90TGeQ9nr5euu2mcowmsPvfy9sQz05GUix9swWRvabjLOn_7NY4EeBaZpeNoOcaWyP1Lh0v42t8d4CMWd7R8qzqB9gQX1w5ykfwEIqNbjiu_cnpgXG42udx302hbSOGdmSiY4boTumD1P_157oSC6CPlahjCqwkw5bZtujtgfPHKlDr2TfnZldswg4MBZx9xm53pXj0iLp3tmdjeTiNWOlirpE5vvgGOT8-iExafSmZ_kdhOB_BSH4nxCfqMkoykdiPlbGRDVC1aKWCTVZOavroqprkWybSrRlJcqyqLp13VIlM6JMFXkxEx1ft12iG-QoeIVZVualEGlRlZnK1kVVdHk2axXknHZSm9SY4y7OtER7f6CmzHmGycDRD2MSsacTG5yAGKema2LMU3vYeMi50T74G0rQwVDzMvbPZZYyuQ7kmN0HvdOvMmjbM8DZ9A0e_dSIgHVycKa5G7w6bA9t2tkd4Cr-0fh62jv7g7oAuBro-WEk8wx_BQAA__-W1qAj">