]> granicus.if.org Git - llvm/commitdiff
[SROA] Function canConvertValue needs to check whether both NewTy and OldTy pointers are
authorJack Liu <jack.liu@intel.com>
Tue, 3 May 2016 19:30:48 +0000 (19:30 +0000)
committerJack Liu <jack.liu@intel.com>
Tue, 3 May 2016 19:30:48 +0000 (19:30 +0000)
pointing to the same addr space. This can prevent SROA from creating a bitcast
between pointers with different addr spaces.

Differential Revision: http://reviews.llvm.org/D19697

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268424 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5980478010db50857cf56ce0cd4d1a7ac85cdb7e..dbc49930f83b2ce2fd8fb1597823d75226afd5b4 100644 (file)
@@ -1635,8 +1635,10 @@ static bool canConvertValue(const DataLayout &DL, Type *OldTy, Type *NewTy) {
   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;
index 5f4df7faadaffc547f8074179170febdba0927ae..119f2252d95eabfb1057bf99c2160743f83d4226 100644 (file)
@@ -52,7 +52,7 @@ define void @test_address_space_0_1(<2 x i64>* %a, i16 addrspace(1)* %b) {
 
 %struct.struct_test_27.0.13 = type { i32, float, i64, i8, [4 x i32] }
 
-; Function Attrs:  nounwind
+; Function Attrs: nounwind
 define void @copy_struct([5 x i64] %in.coerce) {
 ; CHECK-LABEL: @copy_struct(
 ; CHECK-NOT: memcpy
@@ -66,3 +66,20 @@ for.end:
   ret void
 }
  
+%union.anon = type { i32* }
+
+@g = common global i32 0, align 4
+@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
+}