[llvm] [AMDGPU] Improve detection of non-null addrspacecast operands (PR #82311)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 17:53:33 PST 2024


================
@@ -2013,6 +2021,78 @@ bool AMDGPUCodeGenPrepareImpl::visitPHINode(PHINode &I) {
   return true;
 }
 
+bool AMDGPUCodeGenPrepareImpl::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
+  if (!LowerAddrSpaceCast)
+    return false;
+
+  // Check if this can be lowered to a amdgcn.addrspacecast.nonnull.
+  // This is only worthwhile for casts from/to priv/local to flat.
+  const unsigned SrcAS = I.getSrcAddressSpace();
+  const unsigned DstAS = I.getDestAddressSpace();
+
+  bool CanLower = false;
+  if (SrcAS == AMDGPUAS::FLAT_ADDRESS)
+    CanLower = (DstAS == AMDGPUAS::LOCAL_ADDRESS ||
+                DstAS == AMDGPUAS::PRIVATE_ADDRESS);
+  else if (DstAS == AMDGPUAS::FLAT_ADDRESS)
+    CanLower = (SrcAS == AMDGPUAS::LOCAL_ADDRESS ||
+                SrcAS == AMDGPUAS::PRIVATE_ADDRESS);
+  if (!CanLower)
+    return false;
+
+  // Check the Src operand, and look through Phis.
----------------
arsenm wrote:

Can you factor this into a separate helper function, named something like cannotBeNullPointer or similar? I thought we had isKnownNeverNull already but can't seem to find it

https://github.com/llvm/llvm-project/pull/82311


More information about the llvm-commits mailing list