[llvm] IR: Add nonnull flag to addrspacecast (PR #217903)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 05:28:19 PDT 2026
================
@@ -241,3 +241,14 @@ define void @constant_fold_gep_inttoptr() #0 {
store i32 7, ptr addrspace(4) %cast
ret void
}
+
+; nonnull is dropped when a cast-of-cast pair collapses to a single cast.
+define ptr addrspace(1) @drop_nonnull_on_collapsed_castcast(ptr addrspace(3) %p) {
+; CHECK-LABEL: @drop_nonnull_on_collapsed_castcast(
+; CHECK-NEXT: [[B:%.*]] = addrspacecast ptr addrspace(3) [[P:%.*]] to ptr addrspace(1)
+; CHECK-NEXT: ret ptr addrspace(1) [[B]]
+;
+ %a = addrspacecast ptr addrspace(3) %p to ptr
+ %b = addrspacecast nonnull ptr %a to ptr addrspace(1)
+ ret ptr addrspace(1) %b
+}
----------------
arsenm wrote:
That's making a target assumption. A specific address space combination could result in a new null pointer. A target could implement addrspacecast such that a cast that doesn't resolve to a pointer in the target address space returns null. i.e., it could act like OpenCL `to_local`/`to_private`. Relatedly, this is another change I've thought about making to addrspacecast. That would allow genericizing address space predicates across all the GPU targets to a null check against an addrspacecast. In that case we'd want yet another flag to assert the object resolves in the target address space
https://github.com/llvm/llvm-project/pull/217903
More information about the llvm-commits
mailing list