[PATCH] D39432: InferAddressSpaces: Fix bug about replacing addrspacecast

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 14:20:22 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL316957: InferAddressSpaces: Fix bug about replacing addrspacecast (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D39432?vs=120882&id=120888#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39432

Files:
  llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll


Index: llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll
===================================================================
--- llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll
+++ llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll
@@ -15,6 +15,19 @@
   ret void
 }
 
+; CHECK-LABEL: @addrspacecast_different_pointee_type(
+; CHECK: [[GEP:%.*]] = getelementptr i32, i32 addrspace(3)* %ptr, i64 9
+; CHECK: [[CAST:%.*]] = bitcast i32 addrspace(3)* [[GEP]] to i8 addrspace(3)*
+; CHECK-NEXT: store i8 8, i8 addrspace(3)* [[CAST]], align 8
+; CHECK-NEXT: ret void
+define void @addrspacecast_different_pointee_type(i32 addrspace(3)* %ptr) {
+  %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32 addrspace(4)*
+  %gep0 = getelementptr i32, i32 addrspace(4)* %asc0, i64 9
+  %asc1 = addrspacecast i32 addrspace(4)* %gep0 to i8 addrspace(3)*
+  store i8 8, i8 addrspace(3)* %asc1, align 8
+  ret void
+}
+
 ; CHECK-LABEL: @addrspacecast_to_memory(
 ; CHECK: %gep0 = getelementptr i32, i32 addrspace(3)* %ptr, i64 9
 ; CHECK-NEXT: store volatile i32 addrspace(3)* %gep0, i32 addrspace(3)* addrspace(1)* undef
Index: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -971,6 +971,11 @@
         if (AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(CurUser)) {
           unsigned NewAS = NewV->getType()->getPointerAddressSpace();
           if (ASC->getDestAddressSpace() == NewAS) {
+            if (ASC->getType()->getPointerElementType() !=
+                NewV->getType()->getPointerElementType()) {
+              NewV = CastInst::Create(Instruction::BitCast, NewV,
+                                      ASC->getType(), "", ASC);
+            }
             ASC->replaceAllUsesWith(NewV);
             DeadInstructions.push_back(ASC);
             continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39432.120888.patch
Type: text/x-patch
Size: 2038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171030/2f4a6d1c/attachment.bin>


More information about the llvm-commits mailing list