1; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2; RUN: llc -mtriple=aarch64-linux-gnu -O0 -global-isel -stop-after=irtranslator -o - %s | FileCheck %s
3
4%type = type [4 x {i8, i32}]
5
6define i8*  @translate_element_size1(i64 %arg) {
7  ; CHECK-LABEL: name: translate_element_size1
8  ; CHECK: bb.1 (%ir-block.0):
9  ; CHECK:   liveins: $x0
10  ; CHECK:   [[COPY:%[0-9]+]]:_(s64) = COPY $x0
11  ; CHECK:   [[C:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
12  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[C]], [[COPY]](s64)
13  ; CHECK:   [[COPY1:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
14  ; CHECK:   $x0 = COPY [[COPY1]](p0)
15  ; CHECK:   RET_ReallyLR implicit $x0
16  %tmp = getelementptr i8, i8* null, i64 %arg
17  ret i8* %tmp
18}
19
20define %type* @first_offset_const(%type* %addr) {
21
22  ; CHECK-LABEL: name: first_offset_const
23  ; CHECK: bb.1 (%ir-block.0):
24  ; CHECK:   liveins: $x0
25  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
26  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
27  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C]](s64)
28  ; CHECK:   $x0 = COPY [[PTR_ADD]](p0)
29  ; CHECK:   RET_ReallyLR implicit $x0
30  %res = getelementptr %type, %type* %addr, i32 1
31  ret %type* %res
32}
33
34define %type* @first_offset_trivial(%type* %addr) {
35
36  ; CHECK-LABEL: name: first_offset_trivial
37  ; CHECK: bb.1 (%ir-block.0):
38  ; CHECK:   liveins: $x0
39  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
40  ; CHECK:   [[COPY1:%[0-9]+]]:_(p0) = COPY [[COPY]](p0)
41  ; CHECK:   $x0 = COPY [[COPY1]](p0)
42  ; CHECK:   RET_ReallyLR implicit $x0
43  %res = getelementptr %type, %type* %addr, i32 0
44  ret %type* %res
45}
46
47define %type* @first_offset_variable(%type* %addr, i64 %idx) {
48
49  ; CHECK-LABEL: name: first_offset_variable
50  ; CHECK: bb.1 (%ir-block.0):
51  ; CHECK:   liveins: $x0, $x1
52  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
53  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
54  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
55  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[COPY1]], [[C]]
56  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64)
57  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
58  ; CHECK:   $x0 = COPY [[COPY2]](p0)
59  ; CHECK:   RET_ReallyLR implicit $x0
60  %res = getelementptr %type, %type* %addr, i64 %idx
61  ret %type* %res
62}
63
64define %type* @first_offset_ext(%type* %addr, i32 %idx) {
65
66  ; CHECK-LABEL: name: first_offset_ext
67  ; CHECK: bb.1 (%ir-block.0):
68  ; CHECK:   liveins: $w1, $x0
69  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
70  ; CHECK:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
71  ; CHECK:   [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32)
72  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
73  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]]
74  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64)
75  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
76  ; CHECK:   $x0 = COPY [[COPY2]](p0)
77  ; CHECK:   RET_ReallyLR implicit $x0
78  %res = getelementptr %type, %type* %addr, i32 %idx
79  ret %type* %res
80}
81
82%type1 = type [4 x [4 x i32]]
83define i32* @const_then_var(%type1* %addr, i64 %idx) {
84
85  ; CHECK-LABEL: name: const_then_var
86  ; CHECK: bb.1 (%ir-block.0):
87  ; CHECK:   liveins: $x0, $x1
88  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
89  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
90  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 272
91  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C]](s64)
92  ; CHECK:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
93  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[COPY1]], [[C1]]
94  ; CHECK:   [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[PTR_ADD]], [[MUL]](s64)
95  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD1]](p0)
96  ; CHECK:   $x0 = COPY [[COPY2]](p0)
97  ; CHECK:   RET_ReallyLR implicit $x0
98  %res = getelementptr %type1, %type1* %addr, i32 4, i32 1, i64 %idx
99  ret i32* %res
100}
101
102define i32* @var_then_const(%type1* %addr, i64 %idx) {
103
104  ; CHECK-LABEL: name: var_then_const
105  ; CHECK: bb.1 (%ir-block.0):
106  ; CHECK:   liveins: $x0, $x1
107  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
108  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
109  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
110  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[COPY1]], [[C]]
111  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64)
112  ; CHECK:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 40
113  ; CHECK:   [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[PTR_ADD]], [[C1]](s64)
114  ; CHECK:   $x0 = COPY [[PTR_ADD1]](p0)
115  ; CHECK:   RET_ReallyLR implicit $x0
116  %res = getelementptr %type1, %type1* %addr, i64 %idx, i32 2, i32 2
117  ret i32* %res
118}
119
120@arr = external global [8 x i32]
121
122define <2 x i32*> @vec_gep_scalar_base(<2 x i64> %offs) {
123  ; CHECK-LABEL: name: vec_gep_scalar_base
124  ; CHECK: bb.1.entry:
125  ; CHECK:   liveins: $q0
126  ; CHECK:   [[COPY:%[0-9]+]]:_(<2 x s64>) = COPY $q0
127  ; CHECK:   [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @arr
128  ; CHECK:   [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p0>) = G_BUILD_VECTOR [[GV]](p0), [[GV]](p0)
129  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
130  ; CHECK:   [[BUILD_VECTOR1:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[C]](s64), [[C]](s64)
131  ; CHECK:   [[MUL:%[0-9]+]]:_(<2 x s64>) = G_MUL [[COPY]], [[BUILD_VECTOR1]]
132  ; CHECK:   [[PTR_ADD:%[0-9]+]]:_(<2 x p0>) = G_PTR_ADD [[BUILD_VECTOR]], [[MUL]](<2 x s64>)
133  ; CHECK:   [[COPY1:%[0-9]+]]:_(<2 x p0>) = COPY [[PTR_ADD]](<2 x p0>)
134  ; CHECK:   $q0 = COPY [[COPY1]](<2 x p0>)
135  ; CHECK:   RET_ReallyLR implicit $q0
136entry:
137  %0 = getelementptr inbounds [8 x i32], [8 x i32]* @arr, i64 0, <2 x i64> %offs
138  ret <2 x i32*> %0
139}
140