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

Jack Liu via llvm-commits llvm-commits at lists.llvm.org
Sun May 1 16:32:12 PDT 2016


liu12295 updated this revision to Diff 55765.
liu12295 marked 3 inline comments as done.
liu12295 added a comment.

Add unit test into existing address-spaces.ll


http://reviews.llvm.org/D19697

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/address-spaces.ll

Index: test/Transforms/SROA/address-spaces.ll
===================================================================
--- test/Transforms/SROA/address-spaces.ll
+++ test/Transforms/SROA/address-spaces.ll
@@ -66,3 +66,20 @@
   ret void
 }
  
+%union.anon = type { i32* }
+
+ at g = common global i32 0, align 4
+ at l = common addrspace(3) global i32 0, align 4
+
+; Make sure an illegal bitcast isn't introduced
+define void @pr27557() {
+; CHECK-LABEL: @pr27557(
+; CHECK: %[[CAST:.*]] = bitcast i32** {{.*}} to i32 addrspace(3)**
+; CHECK: store i32 addrspace(3)* @l, i32 addrspace(3)** %[[CAST]]
+  %1 = alloca %union.anon, align 8
+  %2 = bitcast %union.anon* %1 to i32**
+  store i32* @g, i32** %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.55765.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160501/4b931fe4/attachment.bin>


More information about the llvm-commits mailing list