<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151785>151785</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Non alloca pointer in llvm.lifetime.end appeared after GVN
</td>
</tr>
<tr>
<th>Labels</th>
<td>
regression,
crash-on-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
e-kud
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/sK5aYrfhs
```llvm
define ptr @foobar(ptr %this, ptr %RHS) {
entry:
store volatile i32 0, ptr %this, align 4
%call2 = call ptr @bar(ptr %this, ptr %RHS)
ret ptr %call2
}
define ptr @bar(ptr %this, ptr %RHS) {
entry:
%cmp = icmp eq ptr %this, %RHS
call void @llvm.assume(i1 %cmp)
ret ptr null
}
define i1 @foo(ptr %Builder) {
entry:
%Result = alloca { [24 x i8] }, align 8
%0 = call ptr @foobar(ptr %Result, ptr %Builder)
call void @llvm.lifetime.end.p0(i64 0, ptr %Result)
ret i1 false
}
```
`opt -O2` produces
```
llvm.lifetime.start/end can only be used on alloca
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %Builder)
```
It is a result of GVN
```llvm
; *** IR Dump After MergedLoadStoreMotionPass on foo ***
define i1 @foo(ptr readnone captures(address) %Builder) local_unnamed_addr {
entry:
%Result = alloca { [24 x i8] }, align 8
store volatile i32 0, ptr %Result, align 4
%cmp.i.i = icmp eq ptr %Result, %Builder
call void @llvm.assume(i1 %cmp.i.i)
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %Result)
ret i1 false
}
; *** IR Dump After GVNPass on foo ***
define i1 @foo(ptr readnone captures(address) %Builder) local_unnamed_addr {
entry:
%Result = alloca { [24 x i8] }, align 8
store volatile i32 0, ptr %Result, align 4
%cmp.i.i = icmp eq ptr %Result, %Builder
call void @llvm.assume(i1 %cmp.i.i)
call void @llvm.lifetime.end.p0(i64 0, ptr nonnull %Builder)
ret i1 false
}
```
Related to https://github.com/llvm/llvm-project/pull/149838 cc @nikic
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVsGO2zYQ_RrqMrBAUaItH3SwYzgN2myLDRCgp4ASRzYbilRJyuj26wtK68j27nbTRS8BCJgWOMP33rwZSXivDgaxInxL-C4RQzhaV-Hi6yCT2sqH6hhC70m-IWxP2P5gZW11SK07ELb_m7C9_5mL31179IRu4lrSaWl96gjdSGyVQeiDA1LQ1tpaOMLK8T_j4ag8Ye_g8e_9T58IWwNZbQndoAnuIV5MNwA-WIdwsloEpRFUzoBeBJ7zCK0OBooxhDDeCK0ZkHwHcXcG8TqCMd5hOD8d80Ryq93E8prV2yjFvF0_olNxg3_esnkMj4dH_CerZLwvSpsK74cOCStV9pjqFrgZtH4GdDw_VmLGvB2UluheBnqPftBhxCq0to2I54DwLSvgL1Al4TuI93wrQXmOpE_kv_XAlPtCshnNC9S1ajGoDlM0Mu1p1GBZXPnhnHMWRGXQCu1xFuRs1Glv-wCLXxlZUuidlUOD_ubQ9dU-CBcI26OR0AgD1ugHqBEGjxKseZQpXv-f8RtrYumeSHEJ5kMA5UGAmwpjW3j_-e6Z9iP5FgjbTAs-3MNu6HrYtAEdfER3QPmLFfJT7K6PNihrfhPeR_yttXPgy-ZxKKSxBqERfRgcesJKIaVD70c3XXkrKqK_DMaIDuWXeOx_tdsrM2L22e2U6PpUpeq5TpxjLph8bz_GpG828YUJvsfM_1Lm95_vfuCivqmqP0BRr4fc6xOKbu5Ri4ASgoWbd7IKx6FOG9sRth_7fvpZ9M7-gU2cUn18FbB9VqzLvISmiYCN-qoaSGSVy3W-FglW2YoXdJ2tc54cK9GWhcxEvWolZjktmcyKZSlqXvKc1u06URWjjNOSZiwveM7TFS2XLV9jW8i2ZZiTgmInlE5Haaw7JMr7AauMZ6uSJ1rUqP344cGYw0O0l7KGMEbYO8JY44Q_LqxZnIRWMj7mu8RVI7N6OPioufLBz-mDChqru2_TF3qrTGwBZeBJeUD0PQqHEsS5TZLB6dvvnde1HUn5qO7E61SxfwIAAP__cgvQGw">