<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64620>64620</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Memory intrinsic lowering should try to simplify based on size bounds
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AMDGPU,
llvm:codegen
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
arsenm
</td>
</tr>
</table>
<pre>
The testcase from #63986 was triggered by poor optimization of the size bounds.
The copy size has a known bound like this:
` %spec.select = tail call i64 @llvm.umin.i64(i64 sub (i64 ptrtoint (ptr addrspacecast (ptr addrspace(4) inttoptr (i64 32 to ptr addrspace(4)) to ptr) to i64), i64 ptrtoint (ptr addrspacecast (ptr addrspace(4) null to ptr) to i64)), i64 56)`
After PreISelIntrinsicLowering, the size check looks like this:
```
%1 = udiv i64 %spec.select, 16
%2 = urem i64 %spec.select, 16
%3 = sub i64 %spec.select, %2
%4 = icmp ne i64 %1, 0
```
InstCombine could clean this up nicely, but this runs really late so that never happens. The backend ends up seeing a non-constant folded and instruction. We should probably try to apply some simplifications based on the known copy size range, even if it's unknown.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVF2L6zYQ_TXyy7DBkRVv_OCHdEPKQi9caEuf9TGx1ciS0ci7-P76Ijl7dy9dSrkQYml0ZqQ5R0eSyA4esWeHX9jhXMkljSH2MhL6qVLBrP0fI0JCSloSwjWGCRhv2qY7tvAqCVK0w4ARDagV5hAihDnZyX6TyQYP4QppRCD7DUGFxRvasfrM6tP2n4vrMK8bAEZJIOHmw6vf0ODsDSGNllhzT2FtDYwfaEa9I3SoE7DmDElaB1o6B7YVwETt3Mu0Wybrd7YVjB9zmBYF9-GcYgrWpzyfUwRpTKRZatSS_h1k_CgY78D6lEJeuVdpOKQAn0Ezelu6j8opOsaf4Oe394tzn1f9XvjQ5klbf2T5dE0Y4WvE59_RPfsUrSerfwuvGK0fcuZ3jfSI-gYuhBt9xv2bAvdfmUKWY19EWIx92fj_QaC8w779gOYbOuL0f9BNQWftPgfngh_gosCtnmbw-Jayz8D6P7p49pSewqSszzdycQa0Q-lL_7DM4K1Gt-YqaklbNC6eIKJ0bgUnEwIFSKNM4PEFI4xyntHTDvIlV1Lf0BtAb0o5QrR-AAk--AcdPCXpE1yDM2hAegPWU4qLzibawV8INJZDzTEoqdwKKa5ZfznPbgUKU9Zvmp29Wl2cR6AkoYHgi7ibp96tFqUfMHeDL-jBXsEmxh8JFl-QP5i0Mn1juqaTFfb7tts_todadNXYHzXi4SCv6rEWQnEpWiWV6GqsTdtyISrb85o39XG_3wsh6m5nsJNdJ9vHTh2V2DdM1DhJ63bFrSEOlSVasG9Fy-vKSYWOytvE-Z1B1pxOX86_fv2Tcc74E-M8p7LmpIPBAX0OH85V7HP4QS0D5bfAUqL3PZJNDvsvOIW4ZktvfgB3N8Qb13eK77yu74R-eM2qJbp-TGkuJuEXxi-DTeOidjpMjF_K4bbPwxzD3-XKXkqTxPil9PlPAAAA___5sb67">