[PATCH] D34991: [InferAddressSpaces] Fix assertion about null pointer

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 4 12:36:20 PDT 2017


yaxunl created this revision.
Herald added subscribers: Anastasia, nhaehnle, wdng.

InferAddressSpaces does not check address space in collectFlatAddressExpressions,
which causes values with non flat address space put into Postorder and causes
assertion in cloneValueWithNewAddressSpace.

This patch fixes assertion in OpenCL 2.0 conformance test generic_address_space
subtest for amdgcn target.


https://reviews.llvm.org/D34991

Files:
  lib/Transforms/Scalar/InferAddressSpaces.cpp
  test/Transforms/InferAddressSpaces/AMDGPU/basic.ll


Index: test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
===================================================================
--- test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
+++ test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
@@ -170,4 +170,16 @@
   ret { i32 addrspace(4)*, i1 } %ret
 }
 
+; Null pointer in local addr space
+; CHECK-LABEL: @local_nullptr
+; CHECK: addrspacecast (i8* null to i8 addrspace(3)*)
+; CHECK-NOT: i8 addrspace(3)* null
+define void @local_nullptr(i32 addrspace(1)* nocapture %results, i8 addrspace(3)* %a) {
+entry:
+  %tobool = icmp ne i8 addrspace(3)* %a, addrspacecast (i8* null to i8 addrspace(3)*)
+  %conv = zext i1 %tobool to i32
+  store i32 %conv, i32 addrspace(1)* %results, align 4
+  ret void
+}
+
 attributes #0 = { nounwind }
Index: lib/Transforms/Scalar/InferAddressSpaces.cpp
===================================================================
--- lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -358,7 +358,8 @@
     // If the operands of the expression on the top are already explored,
     // adds that expression to the resultant postorder.
     if (PostorderStack.back().second) {
-      Postorder.push_back(TopVal);
+      if (TopVal->getType()->getPointerAddressSpace() == FlatAddrSpace)
+        Postorder.push_back(TopVal);
       PostorderStack.pop_back();
       continue;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34991.105195.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170704/a5d2156b/attachment-0001.bin>


More information about the llvm-commits mailing list