<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/141840>141840</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DirectX] DXILCBufferAccess pass is removing globals without replacing all uses
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Icohedron
</td>
</tr>
</table>
<pre>
Discussed issue #141673 with @bogner and came to the conclusion that the underlying issue is that the DXILCBufferAccess pass is removing globals from the module without replacing all their uses, thus resulting in invalid IR.
This notably occurs when the `memcpy` intrinsic uses a global, as seen in #141673 and in this reproduction: https://godbolt.org/z/dn8fYd6bx
In this reproduction, the constant buffer global `@someGlobal` is being used by `memcpy` despite `@someGlobal` not being defined in the module.
To resolve this, the DXILCBufferAccess should be made to handle `memcpy` intrinsics.
Additionally, there should be a check added to ensure that all uses of a global handle are replaced before the global handle is erased from the module.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE1v2zgQ_TXUZRBDoj4sH3RwYnhhYE-LPWSPFDmyuKVIg0M6dX99QUZu0jQ99CRAmnnz5s17EkT6bBEH1j6y9lCIGGbnh5N0MyrvbDE6dRsOmmQkQgWaKCIwXldN1W1reNFhBtaUoztb9CCsAikWhOAgzAjSWWkiaWchzCLkd9Eq9Oam7XlF0_T28fB8-vvpMU4T-r2USAQXQZRKPC7umprOxo3CEEzeLblncSoazFRcDODxYoRMlcKYVKA9REJi_AnCHBMSRRPyfAvaXoXRCk7_bFi5Z-X-31kTWBfEaG7gpIye4GVGm0exrlxwkZcb60rQNnhtScsMD2JlluYIAkJM6O-0SuLohJO3uXinogzaWVbvYQ7hQqzeM35k_Hh2anQmbJw_M378xvhR2X76T3XjV1buT59h5OWy4BSEDTBmDVdKiTdrSnIL_vXKMdEnGDGpENNhx9vPyymkiw74aad1YW1VOGmL61r3S9yFdElpZ66Y6d4Z_nphml00CkaERahsnVlYZX6nNiX8vVI67S2Mua3IHt8hCZAzyi8glEKVINFS9PhqtOSLfDI3_bjafabwuDooiYKTy034oUoToBdJtw8uTNwKNdRqV-9EgUO1bfqmq3a7rpiHqi65UNsKRVd1zdQLpWrJ677p-rYs27rQAy95W7a8r3ZtXXWbpu2rthVy18tp2vKeNSUuQpuNMdcl2aPIERqqpuqbsjBiREM5y5xbfHkNGOM8RdsPqelhjGdiTWk0BXqDCTqY_BM4aI8yPLP28CdZ_Dx7SeMiejN8cLcOcxw30i2MHxOD9fFw8e5_lIHxY-ZNjB_Xxa4D_x4AAP__hcWU1g">