R600: Expand vector FSQRT ops
[oota-llvm.git] / test / CodeGen / R600 / indirect-addressing.ll
1 ; RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck %s
2
3 ; This test checks that uses and defs of the AR register happen in the same
4 ; instruction clause.
5
6 ; CHECK: @mova_same_clause
7 ; CHECK: MOVA_INT
8 ; CHECK-NOT: ALU clause
9 ; CHECK: 0 + AR.x
10 ; CHECK: MOVA_INT
11 ; CHECK-NOT: ALU clause
12 ; CHECK: 0 + AR.x
13
14 define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
15 entry:
16   %stack = alloca [5 x i32], align 4
17   %0 = load i32 addrspace(1)* %in, align 4
18   %arrayidx1 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %0
19   store i32 4, i32* %arrayidx1, align 4
20   %arrayidx2 = getelementptr inbounds i32 addrspace(1)* %in, i32 1
21   %1 = load i32 addrspace(1)* %arrayidx2, align 4
22   %arrayidx3 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %1
23   store i32 5, i32* %arrayidx3, align 4
24   %arrayidx10 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 0
25   %2 = load i32* %arrayidx10, align 4
26   store i32 %2, i32 addrspace(1)* %out, align 4
27   %arrayidx12 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 1
28   %3 = load i32* %arrayidx12
29   %arrayidx13 = getelementptr inbounds i32 addrspace(1)* %out, i32 1
30   store i32 %3, i32 addrspace(1)* %arrayidx13
31   ret void
32 }
33
34 ; This test checks that the stack offset is calculated correctly for structs.
35 ; All register loads/stores should be optimized away, so there shouldn't be
36 ; any MOVA instructions.
37 ;
38 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
39 ; this.
40
41 ; CHECK: @multiple_structs
42 ; CHECK-NOT: MOVA_INT
43
44 %struct.point = type { i32, i32 }
45
46 define void @multiple_structs(i32 addrspace(1)* %out) {
47 entry:
48   %a = alloca %struct.point
49   %b = alloca %struct.point
50   %a.x.ptr = getelementptr %struct.point* %a, i32 0, i32 0
51   %a.y.ptr = getelementptr %struct.point* %a, i32 0, i32 1
52   %b.x.ptr = getelementptr %struct.point* %b, i32 0, i32 0
53   %b.y.ptr = getelementptr %struct.point* %b, i32 0, i32 1
54   store i32 0, i32* %a.x.ptr
55   store i32 1, i32* %a.y.ptr
56   store i32 2, i32* %b.x.ptr
57   store i32 3, i32* %b.y.ptr
58   %a.indirect.ptr = getelementptr %struct.point* %a, i32 0, i32 0
59   %b.indirect.ptr = getelementptr %struct.point* %b, i32 0, i32 0
60   %a.indirect = load i32* %a.indirect.ptr
61   %b.indirect = load i32* %b.indirect.ptr
62   %0 = add i32 %a.indirect, %b.indirect
63   store i32 %0, i32 addrspace(1)* %out
64   ret void
65 }
66
67 ; Test direct access of a private array inside a loop.  The private array
68 ; loads and stores should be lowered to copies, so there shouldn't be any
69 ; MOVA instructions.
70
71 ; CHECK: @direct_loop
72 ; CHECK-NOT: MOVA_INT
73
74 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
75 entry:
76   %prv_array_const = alloca [2 x i32]
77   %prv_array = alloca [2 x i32]
78   %a = load i32 addrspace(1)* %in
79   %b_src_ptr = getelementptr i32 addrspace(1)* %in, i32 1
80   %b = load i32 addrspace(1)* %b_src_ptr
81   %a_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
82   store i32 %a, i32* %a_dst_ptr
83   %b_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 1
84   store i32 %b, i32* %b_dst_ptr
85   br label %for.body
86
87 for.body:
88   %inc = phi i32 [0, %entry], [%count, %for.body]
89   %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
90   %x = load i32* %x_ptr
91   %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
92   %y = load i32* %y_ptr
93   %xy = add i32 %x, %y
94   store i32 %xy, i32* %y_ptr
95   %count = add i32 %inc, 1
96   %done = icmp eq i32 %count, 4095
97   br i1 %done, label %for.end, label %for.body
98
99 for.end:
100   %value_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
101   %value = load i32* %value_ptr
102   store i32 %value, i32 addrspace(1)* %out
103   ret void
104 }