[PATCH] D63525: LangRef: Attempt to formulate some rules for addrspacecast

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 11:21:19 PDT 2020


anna added a comment.

Just chiming in here. We are planning to use addrspacecast for pointer width conversion (32 to 64 bit and vice-versa). Does not change the memory in anyway, i.e. if we lowered the addrspacecast into an IR call, that call could be marked `argmemonly readnone`. However, it is *not* a simple sign-extend/truncate either. 
I've added some comments inline. Also, I think we have the scope to improve optimizations for addrspacecast at IR level, which is currently limited because different targets have varying lowering for addrspacecast.

Specifically, things like "looking through" an addrspacecast when the source operand of AS is nonnull and noting that the result is nonnull as well (i.e. improvements to `isKnownNonZero` and `computeKnownBits`). I was initially leaning towards adding a metadata for special addrspacecast semantics. However, @arsenm mentioned his ideas on adding information in the datalayout, i.e. 0 is a null pointer value for specific addrspaces. The latter may flow nicely with existing optimizations.



================
Comment at: docs/LangRef.rst:9716
+space conversion produces a dereferenceable result then both result and
+operand refer to the same memory location. The conversion must have no
+side effects, or capture the value of the pointer.
----------------
I believe this by itself is a very good statement/property to add to the langref and Verifier.


================
Comment at: docs/LangRef.rst:9722
+
+If the source is not :ref:`poison <poisonvalues>`, and both source and
+destination address spaces are :ref:`integral pointers
----------------
This rule allows us to optimize away redundant addrspacecasts. 
We should be able to eliminate back-to-back addrspacecast when the source and result are dereferenceable, something like:
```
    %v.32 = addrspacecast i8 addrspace(1)* %v.64 to i8 addrspace(2)*
    %v.64.copy = addrspacecast i8 addrspace(2)* to i8 addrspace(1)*
 ```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63525/new/

https://reviews.llvm.org/D63525





More information about the llvm-commits mailing list