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