<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126823>126823</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] Optimize invalid `addrspacecast` to `poison`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
justinfargnoli
</td>
</tr>
</table>
<pre>
LGTM
> Here's an idea, instead of laundering the pointer, what if we return an obviously broken pointer with the value that would provide a strong hint that things went wrong. E.g. 0xebadca51 ("Error BAD CAST") for 32-bit pointers and (0xebadca51 | dst_as<<16 | src_as). This will most likely crash and the distinct constant value would be reasonably easy to search for in the sources.
I personally prefer using undef in this case as opposed to a value with a message in the hex representation. undef (or implicit def in ptx) seems like it will allow for more optimization both during SDAG and ptxas. If we want to be more user friendly maybe using DiagnosticInfo to report the invalid cast similar to AMDGPU would be the way to go.
I think a good follow up would be using `InstCombiner::isValidAddrSpaceCast` in InstCombine to convert invalid casts to poison, though there may be something I'm missing about the semantics here.
_Originally posted by @AlexMaclean in https://github.com/llvm/llvm-project/pull/125607#pullrequestreview-2604027657_
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVMFu47gS_Br60hhBoizJPvjgsSfzArzBLDDZvQaU2JI4oUgtu2XF-_UL0g6SHNcHGyZZ3VXVRSoiMzjEg6i-iuq8UQuPPhx-L8TG9SoMzluzab2-HuDT5__fn36I_Czy4_27_Ab_w4BCNgTKgdGohDyBccSoNPgerFqcxmDcADwizN44xhAPraNiMD2sCAF5CS5W8O3F-IXsFdrgX9C9AWA1PKYKF2UXBI7g1S9Wwxz8xWgEBcTBuwFG4_h2gEfjBoIVHcMa9zL4lg0Z5K_YKt2pqgAhd0LKbyH4AF-PZzgdfz0JKYXcQ-8DlPJLa_iNRRSpI-RjgeYEmvhZkShPojwVdVqi0MUluc_gaTQEq7EWJk8M1rygvUIXFI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