https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115034
Bug ID: 115034
Summary: Missed optimization: reduntant store of identical
value in the slot
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xxs_chy at outlook dot com
Target Milestone: ---
Godbolt link: https://godbolt.org/z/fdxKaxGoj
```
int src(int* outl, bool c1, bool c2) {
int a;
*outl = 0;
if (c1)
if (c2) {
dummy();
return 0;
} else {
a = 1;
}
else {
// we don't need to assign a = 0
a = 0;
}
*outl = a;
return 0;
}
```
can be transformed into:
```
int tgt(int* outl, bool c1, bool c2) {
int a;
*outl = 0;
if (c1) {
if (c2) {
dummy();
return 0;
} else {
a = 1;
}
} else {
return 0;
}
*outl = 1;
return 0;
}
```
Because "*outl = 0" is known at the entry, the path "a = 0 -> *outl = 0" can be
cut off. That is, we can move "*outl = 1" into the path where c1 is true.