Canonicalize addrspacecast ConstExpr between different pointer types
[oota-llvm.git] / test / Transforms / InstCombine / constant-fold-address-space-pointer.ll
index 9b17847cbd22fce0ffa3416de302472da4f523a2..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
@@ -74,6 +74,14 @@ define i8 @const_fold_ptrtoint_mask() {
   ret i8 ptrtoint (i32 addrspace(3)* inttoptr (i32 257 to i32 addrspace(3)*) to i8)
 }
 
+; Address space 0 is too small for the correct mask, should mask with
+; 64-bits instead of 32
+define i64 @const_fold_ptrtoint_mask_small_as0() {
+; CHECK-LABEL: @const_fold_ptrtoint_mask_small_as0(
+; CHECK: ret i64 -1
+  ret i64 ptrtoint (i32 addrspace(1)* inttoptr (i128 -1 to i32 addrspace(1)*) to i64)
+}
+
 define i32 addrspace(3)* @const_inttoptr() {
 ; CHECK-LABEL: @const_inttoptr(
 ; CHECK-NEXT: ret i32 addrspace(3)* inttoptr (i16 4 to i32 addrspace(3)*)
@@ -222,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
+}