Canonicalize addrspacecast ConstExpr between different pointer types
[oota-llvm.git] / test / Transforms / InstCombine / constant-fold-address-space-pointer.ll
index f3a474a8514663f3c6561304e36b263761ae67d8..7fac78a40f569f47b1293f4f3fa1a05bcac453dd 100644 (file)
@@ -32,10 +32,10 @@ define i32 addrspace(2)* @test_constant_fold_inttoptr_as_pointer_smaller() {
 }
 
 ; Different address spaces that are the same size, but they are
-; different so there should be a bitcast.
+; different so nothing should happen
 define i32 addrspace(4)* @test_constant_fold_inttoptr_as_pointer_smaller_different_as() {
 ; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_smaller_different_as(
-; CHECK-NEXT: ret i32 addrspace(4)* bitcast (i32 addrspace(3)* @const_zero_i32_as3 to i32 addrspace(4)*)
+; CHECK-NEXT: ret i32 addrspace(4)* inttoptr (i16 ptrtoint (i32 addrspace(3)* @const_zero_i32_as3 to i16) to i32 addrspace(4)*)
   %x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i16
   %y = inttoptr i16 %x to i32 addrspace(4)*
   ret i32 addrspace(4)* %y
@@ -230,3 +230,13 @@ define i32 @constant_through_array_as_ptrs() {
   %b = load i32 addrspace(1)* %a, align 4
   ret i32 %b
 }
+
+@shared_mem = external addrspace(3) global [0 x i8]
+
+define float @canonicalize_addrspacecast(i32 %i) {
+; CHECK-LABEL: @canonicalize_addrspacecast
+; CHECK-NEXT: getelementptr inbounds float* addrspacecast (float addrspace(3)* bitcast ([0 x i8] addrspace(3)* @shared_mem to float addrspace(3)*) to float*), i32 %i
+  %p = getelementptr inbounds float* addrspacecast ([0 x i8] addrspace(3)* @shared_mem to float*), i32 %i
+  %v = load float* %p
+  ret float %v
+}