[llvm-dev] ptrtoint > addrspacecast is disallowed

Harald van Dijk via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 30 01:43:35 PDT 2021


Hi,

The semantics of addrspacecast 
(https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction) are:

    The ‘|addrspacecast|’ instruction converts the pointer value
    |ptrval| to type |pty2|. _It can be a __/no-op cast/__or a complex
    value modification, depending on the target and the address space
    pair._ Pointer conversions within the same address space must be
    performed with the |bitcast| instruction. Note that if the address
    space conversion is legal then both result and operand refer to the
    same memory location.

So whether it is valid for instcombine to optimise your example depends 
on the target. It would be wrong for instcombine to unconditionally 
optimise this to i64 3098316506530080114. It might be possible to extend 
it to optimise this when the optimisation is valid by getting extra 
information from the target, there is a isNoopAddrSpaceCast function 
already that can be used to determine whether it is valid, but the 
function you are looking at is target-independent, it cannot get target 
info. It will require some thought on the design.

On 30/07/2021 08:19, Kavindu Gimhan Zoysa via llvm-dev wrote:
> Hi all,
>
> *ptrtoint (i8* addrspacecast (i8 addrspace(1)* inttoptr (i64 
> 3098316506530080114 to i8 addrspace(1)*) to i8*) to i64)*
>
> As shown here 
> <https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Instructions.cpp#L2797>, 
> ptrtoint -> addrspacecast is disallowed in *instcombine* pass. Can you 
> please explain to me the reason behind this?
>
> If I run the *instcombine* pass against the above instructions, 
> nothing happens. But if I remove it, the code got optimized.
>
> Thank you,
> Kavindu
>
> Kavindu Gimhan Zoysa,
> BSc(Hons) | ENTC | UoM,
> ATL | WSO2
>
> GitHub <https://github.com/KavinduZoysa> LinkedIn 
> <https://www.linkedin.com/in/kavindu-gimhan-zoysa-85939a122/> Medium 
> <https://medium.com/@kavindugimhanzoysa>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210730/857852de/attachment.html>


More information about the llvm-dev mailing list