<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59312>59312</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed GVN/PRE for load instruction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
weiguozhi
</td>
</tr>
</table>
<pre>
Compile the test case with
```
clang -fno-omit-frame-pointer -fno-exceptions -O3 -c reduce2.ii -o reduce2.o --save-temps
struct u {
bool ax();
void bc();
bool bd();
long az;
long bb;
};
inline bool u::ax() {
if (bb > az)
return true;
if (bd())
return false;
return true;
}
inline void u::bc() {
if (!ax())
return;
az++;
return;
}
inline void foo(u *v) {
if (!v->ax())
return;
if (v->az)
v->bc();
v->bc();
}
void bv(int l, int e) {
for (; l!=e; ++l) {
u m;
while (m.ax())
foo(&m);
}
}
```
I got
```
...
incq %rcx
movq %rcx, -40(%rbp)
.LBB0_18: # %_Z3fooP1u.exit
# in Loop: Header=BB0_3 Depth=2
movq -40(%rbp), %rcx // 1
...
testb %al, %al
jne .LBB0_18
# %bb.8: # %if.endthread-pre-split.i
# in Loop: Header=BB0_3 Depth=2
movq -40(%rbp), %rcx // 2
...
testb %al, %al
jne .LBB0_18
# %bb.16: # %_ZN1u2axEv.exit.if.end_crit_edge.i12.i
# in Loop: Header=BB0_3 Depth=2
movq -40(%rbp), %rcx // 3
...
```
Instructions 2 and 3 can be moved before jne, then instruction 1 can be deleted.
It looks like a missed GVN/PRE for load instruction.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0ls-PozYUx_8a5_IEguchEw4cJpNJu9J2u-qhh15GNrwE7xpMbZOZ7l9fGQjJJKl2Ku1GiJjn9-PzvtiAcE7tW6KCZWuWbRai97WxxQupfW--1WohTfVP8WiaTmkCXxN4ch5K4QhelK9ZsmHJA1sm0zFcllq0e4h2rYlMo3y0s6Khq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