1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=ALL --check-prefix=X64_GISEL
3; RUN: llc -mtriple=x86_64-linux-gnu              -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=ALL --check-prefix=X64
4
5define i32* @test_gep_i8(i32 *%arr, i8 %ind) {
6; X64_GISEL-LABEL: test_gep_i8:
7; X64_GISEL:       # %bb.0:
8; X64_GISEL-NEXT:    # kill: def $esi killed $esi def $rsi
9; X64_GISEL-NEXT:    movq $4, %rax
10; X64_GISEL-NEXT:    movq $56, %rcx
11; X64_GISEL-NEXT:    # kill: def $cl killed $rcx
12; X64_GISEL-NEXT:    shlq %cl, %rsi
13; X64_GISEL-NEXT:    movq $56, %rcx
14; X64_GISEL-NEXT:    # kill: def $cl killed $rcx
15; X64_GISEL-NEXT:    sarq %cl, %rsi
16; X64_GISEL-NEXT:    imulq %rax, %rsi
17; X64_GISEL-NEXT:    leaq (%rdi,%rsi), %rax
18; X64_GISEL-NEXT:    retq
19;
20; X64-LABEL: test_gep_i8:
21; X64:       # %bb.0:
22; X64-NEXT:    # kill: def $esi killed $esi def $rsi
23; X64-NEXT:    movsbq %sil, %rax
24; X64-NEXT:    leaq (%rdi,%rax,4), %rax
25; X64-NEXT:    retq
26  %arrayidx = getelementptr i32, i32* %arr, i8 %ind
27  ret i32* %arrayidx
28}
29
30define i32* @test_gep_i8_const(i32 *%arr) {
31; X64_GISEL-LABEL: test_gep_i8_const:
32; X64_GISEL:       # %bb.0:
33; X64_GISEL-NEXT:    movq $80, %rax
34; X64_GISEL-NEXT:    leaq (%rdi,%rax), %rax
35; X64_GISEL-NEXT:    retq
36;
37; X64-LABEL: test_gep_i8_const:
38; X64:       # %bb.0:
39; X64-NEXT:    leaq 80(%rdi), %rax
40; X64-NEXT:    retq
41  %arrayidx = getelementptr i32, i32* %arr, i8 20
42  ret i32* %arrayidx
43}
44
45define i32* @test_gep_i16(i32 *%arr, i16 %ind) {
46; X64_GISEL-LABEL: test_gep_i16:
47; X64_GISEL:       # %bb.0:
48; X64_GISEL-NEXT:    # kill: def $esi killed $esi def $rsi
49; X64_GISEL-NEXT:    movq $4, %rax
50; X64_GISEL-NEXT:    movq $48, %rcx
51; X64_GISEL-NEXT:    # kill: def $cl killed $rcx
52; X64_GISEL-NEXT:    shlq %cl, %rsi
53; X64_GISEL-NEXT:    movq $48, %rcx
54; X64_GISEL-NEXT:    # kill: def $cl killed $rcx
55; X64_GISEL-NEXT:    sarq %cl, %rsi
56; X64_GISEL-NEXT:    imulq %rax, %rsi
57; X64_GISEL-NEXT:    leaq (%rdi,%rsi), %rax
58; X64_GISEL-NEXT:    retq
59;
60; X64-LABEL: test_gep_i16:
61; X64:       # %bb.0:
62; X64-NEXT:    # kill: def $esi killed $esi def $rsi
63; X64-NEXT:    movswq %si, %rax
64; X64-NEXT:    leaq (%rdi,%rax,4), %rax
65; X64-NEXT:    retq
66  %arrayidx = getelementptr i32, i32* %arr, i16 %ind
67  ret i32* %arrayidx
68}
69
70define i32* @test_gep_i16_const(i32 *%arr) {
71; X64_GISEL-LABEL: test_gep_i16_const:
72; X64_GISEL:       # %bb.0:
73; X64_GISEL-NEXT:    movq $80, %rax
74; X64_GISEL-NEXT:    leaq (%rdi,%rax), %rax
75; X64_GISEL-NEXT:    retq
76;
77; X64-LABEL: test_gep_i16_const:
78; X64:       # %bb.0:
79; X64-NEXT:    leaq 80(%rdi), %rax
80; X64-NEXT:    retq
81  %arrayidx = getelementptr i32, i32* %arr, i16 20
82  ret i32* %arrayidx
83}
84
85define i32* @test_gep_i32(i32 *%arr, i32 %ind) {
86; X64_GISEL-LABEL: test_gep_i32:
87; X64_GISEL:       # %bb.0:
88; X64_GISEL-NEXT:    movq $4, %rax
89; X64_GISEL-NEXT:    movslq %esi, %rcx
90; X64_GISEL-NEXT:    imulq %rax, %rcx
91; X64_GISEL-NEXT:    leaq (%rdi,%rcx), %rax
92; X64_GISEL-NEXT:    retq
93;
94; X64-LABEL: test_gep_i32:
95; X64:       # %bb.0:
96; X64-NEXT:    movslq %esi, %rax
97; X64-NEXT:    leaq (%rdi,%rax,4), %rax
98; X64-NEXT:    retq
99  %arrayidx = getelementptr i32, i32* %arr, i32 %ind
100  ret i32* %arrayidx
101}
102
103define i32* @test_gep_i32_const(i32 *%arr) {
104; X64_GISEL-LABEL: test_gep_i32_const:
105; X64_GISEL:       # %bb.0:
106; X64_GISEL-NEXT:    movq $20, %rax
107; X64_GISEL-NEXT:    leaq (%rdi,%rax), %rax
108; X64_GISEL-NEXT:    retq
109;
110; X64-LABEL: test_gep_i32_const:
111; X64:       # %bb.0:
112; X64-NEXT:    leaq 20(%rdi), %rax
113; X64-NEXT:    retq
114  %arrayidx = getelementptr i32, i32* %arr, i32 5
115  ret i32* %arrayidx
116}
117
118define i32* @test_gep_i64(i32 *%arr, i64 %ind) {
119; X64_GISEL-LABEL: test_gep_i64:
120; X64_GISEL:       # %bb.0:
121; X64_GISEL-NEXT:    movq $4, %rax
122; X64_GISEL-NEXT:    imulq %rsi, %rax
123; X64_GISEL-NEXT:    leaq (%rdi,%rax), %rax
124; X64_GISEL-NEXT:    retq
125;
126; X64-LABEL: test_gep_i64:
127; X64:       # %bb.0:
128; X64-NEXT:    leaq (%rdi,%rsi,4), %rax
129; X64-NEXT:    retq
130  %arrayidx = getelementptr i32, i32* %arr, i64 %ind
131  ret i32* %arrayidx
132}
133
134define i32* @test_gep_i64_const(i32 *%arr) {
135; X64_GISEL-LABEL: test_gep_i64_const:
136; X64_GISEL:       # %bb.0:
137; X64_GISEL-NEXT:    movq $20, %rax
138; X64_GISEL-NEXT:    leaq (%rdi,%rax), %rax
139; X64_GISEL-NEXT:    retq
140;
141; X64-LABEL: test_gep_i64_const:
142; X64:       # %bb.0:
143; X64-NEXT:    leaq 20(%rdi), %rax
144; X64-NEXT:    retq
145  %arrayidx = getelementptr i32, i32* %arr, i64 5
146  ret i32* %arrayidx
147}
148
149