[llvm-dev] [RFC] : LLVM IR should allow bitcast between address spaces with the same size

Matt Arsenault via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 30 16:27:04 PST 2021



> On Nov 30, 2021, at 04:51, Renato Golin <rengolin at gmail.com> wrote:
> 
> On Mon, 29 Nov 2021 at 18:15, Matt Arsenault <arsenm2 at gmail.com <mailto:arsenm2 at gmail.com>> wrote:
> This is true, but this isn’t directly related to this change. If the target does not have no-op conversions between a given pair of address spaces, the original code was broken to begin with. This change does not allow introducing new illegal address space conversions that were not already present in the original program. It’s garbage in, garbage out. If the target can’t really reinterpret these pointers, it would be UB on access.
> 
> Ah, I see.
> 
> So IIUC, adding the casts in the first place would have to know about target address spaces, but this specific change only allows eliding the inttoptr cast in the specific case where the address spaces have the same data layout?
> 
> Assuming the initial cast was legal to begin with, this looks sensible to me.
The target’s notion of address space casts doesn’t apply here. The user decided to reinterpret the pointer in a different address space, which may or may not be valid to use on the target.

> 
> I was worried this would allow (encourage?) front-ends and other passes to add an address space cast where none (could have) existed in the first place.

No, we’re converting from an in-memory representation of reinterpreting bits to one in values. Frontends still need to have some contextual knowledge of what the language and target expects out of address spaces. 

-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211130/4b0c9913/attachment.html>


More information about the llvm-dev mailing list