Home | History | Annotate | Download | only in SROA
      1 ; RUN: opt < %s -sroa -S | FileCheck %s
      2 target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64-A2"
      3 
      4 declare void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* nocapture, i8 addrspace(2)* nocapture readonly, i32, i1)
      5 declare void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(2)* nocapture readonly, i32, i1)
      6 declare void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
      7 declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
      8 
      9 
     10 
     11 ; CHECK-LABEL: @test_address_space_1_1(
     12 ; CHECK: load <2 x i64>, <2 x i64> addrspace(1)* %a, align 2
     13 ; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(1)* {{.*}}, align 2
     14 ; CHECK: ret void
     15 define void @test_address_space_1_1(<2 x i64> addrspace(1)* %a, i16 addrspace(1)* %b) {
     16   %aa = alloca <2 x i64>, align 16, addrspace(2)
     17   %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
     18   %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
     19   call void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
     20   %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
     21   call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
     22   ret void
     23 }
     24 
     25 ; CHECK-LABEL: @test_address_space_1_0(
     26 ; CHECK: load <2 x i64>, <2 x i64> addrspace(1)* %a, align 2
     27 ; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(2)* {{.*}}, align 2
     28 ; CHECK: ret void
     29 define void @test_address_space_1_0(<2 x i64> addrspace(1)* %a, i16 addrspace(2)* %b) {
     30   %aa = alloca <2 x i64>, align 16, addrspace(2)
     31   %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
     32   %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
     33   call void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
     34   %bptr = bitcast i16 addrspace(2)* %b to i8 addrspace(2)*
     35   call void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
     36   ret void
     37 }
     38 
     39 ; CHECK-LABEL: @test_address_space_0_1(
     40 ; CHECK: load <2 x i64>, <2 x i64> addrspace(2)* %a, align 2
     41 ; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(1)* {{.*}}, align 2
     42 ; CHECK: ret void
     43 define void @test_address_space_0_1(<2 x i64> addrspace(2)* %a, i16 addrspace(1)* %b) {
     44   %aa = alloca <2 x i64>, align 16, addrspace(2)
     45   %aptr = bitcast <2 x i64> addrspace(2)* %a to i8 addrspace(2)*
     46   %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
     47   call void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(2)* align 2 %aptr, i32 16, i1 false)
     48   %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
     49   call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
     50   ret void
     51 }
     52 
     53 %struct.struct_test_27.0.13 = type { i32, float, i64, i8, [4 x i32] }
     54 
     55 ; CHECK-LABEL: @copy_struct(
     56 ; CHECK-NOT: memcpy
     57 define void @copy_struct([5 x i64] %in.coerce) {
     58 for.end:
     59   %in = alloca %struct.struct_test_27.0.13, align 8, addrspace(2)
     60   %0 = bitcast %struct.struct_test_27.0.13 addrspace(2)* %in to [5 x i64] addrspace(2)*
     61   store [5 x i64] %in.coerce, [5 x i64] addrspace(2)* %0, align 8
     62   %scevgep9 = getelementptr %struct.struct_test_27.0.13, %struct.struct_test_27.0.13 addrspace(2)* %in, i32 0, i32 4, i32 0
     63   %scevgep910 = bitcast i32 addrspace(2)* %scevgep9 to i8 addrspace(2)*
     64   call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 4 undef, i8 addrspace(2)* align 4 %scevgep910, i32 16, i1 false)
     65   ret void
     66 }
     67 
     68 %union.anon = type { i32* }
     69 
     70 @g = common global i32 0, align 4
     71 @l = common addrspace(3) global i32 0, align 4
     72 
     73 ; Make sure an illegal bitcast isn't introduced
     74 ; CHECK-LABEL: @pr27557(
     75 ; CHECK: %[[CAST:.*]] = bitcast i32* addrspace(2)* {{.*}} to i32 addrspace(3)* addrspace(2)*
     76 ; CHECK: store i32 addrspace(3)* @l, i32 addrspace(3)* addrspace(2)* %[[CAST]]
     77 define void @pr27557() {
     78   %1 = alloca %union.anon, align 8, addrspace(2)
     79   %2 = bitcast %union.anon addrspace(2)* %1 to i32* addrspace(2)*
     80   store i32* @g, i32* addrspace(2)* %2, align 8
     81   %3 = bitcast %union.anon addrspace(2)* %1 to i32 addrspace(3)* addrspace(2)*
     82   store i32 addrspace(3)* @l, i32 addrspace(3)* addrspace(2)* %3, align 8
     83   ret void
     84 }
     85 
     86 ; Test load from and store to non-zero address space.
     87 define void @test_load_store_diff_addr_space([2 x float] addrspace(1)* %complex1, [2 x float] addrspace(1)* %complex2) {
     88 ; CHECK-LABEL: @test_load_store_diff_addr_space
     89 ; CHECK-NOT: alloca
     90 ; CHECK: load i32, i32 addrspace(1)*
     91 ; CHECK: load i32, i32 addrspace(1)*
     92 ; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
     93 ; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
     94   %a0 = alloca [2 x i64], align 8, addrspace(2)
     95   %a = getelementptr [2 x i64], [2 x i64] addrspace(2)* %a0, i32 0, i32 0
     96   %a.cast = bitcast i64 addrspace(2)* %a to [2 x float] addrspace(2)*
     97   %a.gep1 = getelementptr [2 x float], [2 x float] addrspace(2)* %a.cast, i32 0, i32 0
     98   %a.gep2 = getelementptr [2 x float], [2 x float] addrspace(2)* %a.cast, i32 0, i32 1
     99   %complex1.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex1, i32 0, i32 0
    100   %p1 = bitcast float addrspace(1)* %complex1.gep to i64 addrspace(1)*
    101   %v1 = load i64, i64 addrspace(1)* %p1
    102   store i64 %v1, i64 addrspace(2)* %a
    103   %f1 = load float, float addrspace(2)* %a.gep1
    104   %f2 = load float, float addrspace(2)* %a.gep2
    105   %sum = fadd float %f1, %f2
    106   store float %sum, float addrspace(2)* %a.gep1
    107   store float %sum, float addrspace(2)* %a.gep2
    108   %v2 = load i64, i64 addrspace(2)* %a
    109   %complex2.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex2, i32 0, i32 0
    110   %p2 = bitcast float addrspace(1)* %complex2.gep to i64 addrspace(1)*
    111   store i64 %v2, i64 addrspace(1)* %p2
    112   ret void
    113 }
    114