<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88850>88850</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization : fail to
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
XChy
</td>
</tr>
</table>
<pre>
Alive2 proof: alive2 link
Missed example: godbolt link
### Motivating example
```llvm
define i8 @src(ptr %p, ptr %p1, i1 %c) #0 {
entry:
%add.ptr = getelementptr inbounds i8, ptr %p1, i64 1
%add.ptr1 = getelementptr inbounds i8, ptr %p1, i64 4
store ptr %add.ptr, ptr %p, align 8
store i8 0, ptr %p1, align 1
%cond = select i1 %c, ptr %add.ptr, ptr %add.ptr1
%add.ptr2 = getelementptr inbounds i8, ptr %cond, i64 1
store i8 1, ptr %add.ptr2, align 1
%0 = load i8, ptr %p1, align 1
ret i8 %0
}
```
The loaded value of `%p1` should be 0, but the store to `%add.ptr2` clobbers and resists optimization.
```llvm
define i8 @tgt(ptr %p, ptr %p1, i1 %c) #1 {
%add.ptr = getelementptr inbounds i8, ptr %p1, i64 1
%add.ptr1 = getelementptr inbounds i8, ptr %p1, i64 4
store ptr %add.ptr, ptr %p, align 8
store i8 0, ptr %p1, align 1
%cond = select i1 %c, ptr %add.ptr, ptr %add.ptr1
%add.ptr2 = getelementptr inbounds i8, ptr %cond, i64 1
store i8 1, ptr %add.ptr2, align 1
ret i8 0
}
```
C version: https://godbolt.org/z/n35z81b87
### Real-world motivation
This snippet of IR is derived from [postgres/src/backend/utils/adt/network.c](https://github.com/postgres/postgres/blob/bea97cd02ebb347ab469b78673c2b33a72109669/src/backend/utils/adt/network.c#L1374) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/Tha53z7hc
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height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