[PATCH] D50058: Fix InstCombine address space assert

Ewan Crawford via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 31 08:53:42 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL338395: Fix InstCombine address space assert (authored by EwanCrawford, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50058?vs=158277&id=158293#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50058

Files:
  llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/trunk/test/Transforms/InstCombine/gep-addrspace.ll


Index: llvm/trunk/test/Transforms/InstCombine/gep-addrspace.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/gep-addrspace.ll
+++ llvm/trunk/test/Transforms/InstCombine/gep-addrspace.ll
@@ -65,3 +65,22 @@
   ret { i8, i8 } %insert
 }
 
+
+declare spir_func <16 x i32> @my_extern_func()
+
+; check that a bitcast is not generated when we need an addrspace cast
+define void @bitcast_after_gep(<16 x i32>* %t0) {
+; CHECK-LABEL: @bitcast_after_gep(
+; CHECK-NEXT:    [[T4:%.*]] = addrspacecast <16 x i32>* [[T0:%.*]] to <16 x i32> addrspace(3)*
+; CHECK-NEXT:    [[CALL:%.*]] = call spir_func <16 x i32> @my_extern_func()
+; CHECK-NEXT:    store <16 x i32> [[CALL]], <16 x i32> addrspace(3)* [[T4]], align 64
+; CHECK-NEXT:    ret void
+;
+  %t1 = bitcast <16 x i32>* %t0 to [16 x i32]*
+  %t2 = addrspacecast [16 x i32]* %t1 to [16 x i32] addrspace(3)*
+  %t3 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %t2, i64 0, i64 0
+  %t4 = bitcast i32 addrspace(3)* %t3 to <16 x i32> addrspace(3)*
+  %call = call spir_func <16 x i32> @my_extern_func()
+  store <16 x i32> %call, <16 x i32> addrspace(3)* %t4
+  ret void
+}
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2243,6 +2243,12 @@
     Type *DstElTy = DstPTy->getElementType();
     Type *SrcElTy = SrcPTy->getElementType();
 
+    // Casting pointers between the same type, but with different address spaces
+    // is an addrspace cast rather than a bitcast.
+    if ((DstElTy == SrcElTy) &&
+        (DstPTy->getAddressSpace() != SrcPTy->getAddressSpace()))
+      return new AddrSpaceCastInst(Src, DestTy);
+
     // If we are casting a alloca to a pointer to a type of the same
     // size, rewrite the allocation instruction to allocate the "right" type.
     // There is no need to modify malloc calls because it is their bitcast that


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50058.158293.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180731/9d6b1f7f/attachment.bin>


More information about the llvm-commits mailing list