Add instcombine visitor for addrspacecast
[oota-llvm.git] / test / Transforms / InstCombine / addrspacecast.ll
1 ; RUN: opt -instcombine -S < %s | FileCheck %s
2
3 target datalayout = "e-p:64:64:64-p1:32:32:32-p2:16:16:16-n8:16:32:64"
4
5 define i32* @combine_redundant_addrspacecast(i32 addrspace(1)* %x) nounwind {
6 ; CHECK-LABEL: @combine_redundant_addrspacecast(
7 ; CHECK: addrspacecast i32 addrspace(1)* %x to i32*
8 ; CHECK-NEXT: ret
9   %y = addrspacecast i32 addrspace(1)* %x to i32 addrspace(3)*
10   %z = addrspacecast i32 addrspace(3)* %y to i32*
11   ret i32* %z
12 }
13
14 define <4 x i32*> @combine_redundant_addrspacecast_vector(<4 x i32 addrspace(1)*> %x) nounwind {
15 ; CHECK-LABEL: @combine_redundant_addrspacecast_vector(
16 ; CHECK: addrspacecast <4 x i32 addrspace(1)*> %x to <4 x i32*>
17 ; CHECK-NEXT: ret
18   %y = addrspacecast <4 x i32 addrspace(1)*> %x to <4 x i32 addrspace(3)*>
19   %z = addrspacecast <4 x i32 addrspace(3)*> %y to <4 x i32*>
20   ret <4 x i32*> %z
21 }
22
23 define float* @combine_redundant_addrspacecast_types(i32 addrspace(1)* %x) nounwind {
24 ; CHECK-LABEL: @combine_redundant_addrspacecast_types(
25 ; CHECK: addrspacecast i32 addrspace(1)* %x to float*
26 ; CHECK-NEXT: ret
27   %y = addrspacecast i32 addrspace(1)* %x to i32 addrspace(3)*
28   %z = addrspacecast i32 addrspace(3)* %y to float*
29   ret float* %z
30 }
31