<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131927>131927</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Empty lifetime range removal changes behaviour
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tmiasko
</td>
</tr>
</table>
<pre>
In the example below, allocation `a` and allocation `b` have overlapping
lifetimes in all executions, so it should be impossible to observe them having
the same address. InstCombine removes the overlapping lifetimes. Which
introduces a behavior that wasn't possible before.
Before InstCombine:
```llvm
define { i1, i1 } @f() {
%a = alloca ptr
%b = alloca ptr
; Overlapping lifetimes (removed by instcombine)
call void @llvm.lifetime.start.p0(i64 8, ptr %a)
call void @llvm.lifetime.start.p0(i64 8, ptr %b)
call void @llvm.lifetime.end.p0(i64 8, ptr %a)
call void @llvm.lifetime.end.p0(i64 8, ptr %b)
; Disjoint lifetimes
call void @llvm.lifetime.start.p0(i64 8, ptr %a)
call void @g(ptr %a)
call void @llvm.lifetime.end.p0(i64 8, ptr %a)
call void @llvm.lifetime.start.p0(i64 8, ptr %b)
call void @g(ptr %b)
call void @llvm.lifetime.end.p0(i64 8, ptr %b)
; Obscured equality comparison. Avoids fold that incorrectly assumes that
; "Two distinct allocations will never be equal." See #45725 for details.
%1 = icmp ule ptr %a, %b
%2 = icmp uge ptr %a, %b
%3 = insertvalue { i1, i1 } poison, i1 %1, 0
%4 = insertvalue { i1, i1 } %3, i1 %2, 1
ret { i1, i1 } %4
}
declare void @g(ptr)
```
After InstCombine
```llvm
define { i1, i1 } @f() {
%a = alloca ptr, align 8
%b = alloca ptr, align 8
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %a)
call void @g(ptr nonnull %a)
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %a)
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %b)
call void @g(ptr nonnull %b)
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %b)
%1 = icmp ule ptr %a, %b
%2 = icmp uge ptr %a, %b
%3 = insertvalue { i1, i1 } poison, i1 %1, 0
%4 = insertvalue { i1, i1 } %3, i1 %2, 1
ret { i1, i1 } %4
}
```
https://alive2.llvm.org/ce/z/Vo8GLq
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vk2P2zYQ_TX0ZRCBGtqWfNBBG9dFgAI5tGjPFDW2mFKkQlLabH99QWnX6w2c7keSLhaQSc7Hm0e-IWUI-mSJKra5YZv9So6xc76KvZbhb7dqXHtXfbAQOwL6IvvBEDRk3C3D9yCNcUpG7SywLZdsy0Ha9qvpJk13ciJwE3kjh0HbE-O10UeKuqcA2iYXoC-kxuQVUuzgQEcInRtNCw2B7gcXgm4MQXTgmkB-ogSrT8GXkAlkkD2BbFtPIWQAH2yI713faEvgqXcThbmWCyxwRpLBX51WHeO1ttG7dlQUQEJDKYPzEDsZ4VYGy7CIcMbT0NF5yhivGa9v5sFlXibqZYlt-fJvzNQzXrd0TLBYcQM6TzXrHFixB7bmR4Ylw11aY7wGYLiRwMT-nlsYon-Yb67Oixv4eK1EYFguPLTQ3IG2Iap7mLibXVXai8npNuFISLMH5yxE6WM2cIal3q6hTJiH6Gd03-fevMCdbPv23N90PmdOlO11-OS0jY98_XBKTgzLH4H7pxB-Ae67duQJqR-boEZPLdDnURod70C5fpBeB2czqFPoAEdn2kVf2irnPalo7kCGMPazYmU8x2OIf9w6aHWI2qp40W4C3GpjwNJEPvWMOWHGEOF3ImAo1psCN3B0HlqKUpuQPagon1WkVT_AaOiC5PdLPbxOX7ywOl23Sj_EYmYD-ThJM17R-OBS-Q8TuJnX-H2a9fP-KUsapr8lAqZhPkPwFK96rFMTKvZLN2pJGenp671fdu7cqhbb-hjJP-lpP6OhzTeKPlkov9nbnpq84ehbZ-1ozPP6fNbwJVJ4ZZAXgP5v3T5r-ErQjzp-kUL-L4m8UiNv0cfT89_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