[PATCH] D19697: SROA assertion: creating bitcast between ptr types with different addr spaces

Jack Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 17:08:28 PDT 2016


liu12295 created this revision.
liu12295 added reviewers: sanjoy, chandlerc.
liu12295 added a subscriber: llvm-commits.
liu12295 set the repository for this revision to rL LLVM.

In SROA.cpp's canConvertValue() function, it will return "true" if both NewTy and OldTy are ptr type. Probably we need to check whether those two pointers are pointing to the same addr space; otherwise this will trigger an assertion later when SROA tries to create a bitcast between pointers with different addr spaces.

Repository:
  rL LLVM

http://reviews.llvm.org/D19697

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/pr27557.ll

Index: test/Transforms/SROA/pr27557.ll
===================================================================
--- test/Transforms/SROA/pr27557.ll
+++ test/Transforms/SROA/pr27557.ll
@@ -0,0 +1,19 @@
+; RUN: opt -O1 < %s -S
+
+; ModuleID = '<origin>'
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+
+%union.anon = type { i32 addrspace(1)* }
+
+ at g = common addrspace(1) global i32 0, align 4
+ at l = common addrspace(3) global i32 0, align 4
+
+; Function Attrs: nounwind uwtable
+define void @testKernel() #0 {
+  %1 = alloca %union.anon, align 8
+  %2 = bitcast %union.anon* %1 to i32 addrspace(1)**
+  store i32 addrspace(1)* @g, i32 addrspace(1)** %2, align 8
+  %3 = bitcast %union.anon* %1 to i32 addrspace(3)**
+  store i32 addrspace(3)* @l, i32 addrspace(3)** %3, align 8
+  ret void
+}
Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -1635,8 +1635,10 @@
   OldTy = OldTy->getScalarType();
   NewTy = NewTy->getScalarType();
   if (NewTy->isPointerTy() || OldTy->isPointerTy()) {
-    if (NewTy->isPointerTy() && OldTy->isPointerTy())
-      return true;
+    if (NewTy->isPointerTy() && OldTy->isPointerTy()) {
+      return cast<PointerType>(NewTy)->getPointerAddressSpace() ==
+        cast<PointerType>(OldTy)->getPointerAddressSpace();
+    }
     if (NewTy->isIntegerTy() || OldTy->isIntegerTy())
       return true;
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19697.55507.patch
Type: text/x-patch
Size: 1489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160429/260fab7d/attachment.bin>


More information about the llvm-commits mailing list