1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -mtriple=arm64-apple-ios -S -passes=slp-vectorizer < %s | FileCheck %s
3 ; vectorization requires a vector GEP + extracts, but the cost is offset by being able to efficiently vectorize the rest of the tree
5 define void @should_vectorize_gep(ptr %base1, ptr %base2, ptr %base_gep) {
6 ; CHECK-LABEL: define void @should_vectorize_gep
7 ; CHECK-SAME: (ptr [[BASE1:%.*]], ptr [[BASE2:%.*]], ptr [[BASE_GEP:%.*]]) {
9 ; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr [[BASE1]], align 2
10 ; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i32> [[TMP0]] to <4 x i64>
11 ; CHECK-NEXT: [[TMP2:%.*]] = load <4 x i32>, ptr [[BASE2]], align 2
12 ; CHECK-NEXT: [[TMP3:%.*]] = zext <4 x i32> [[TMP2]] to <4 x i64>
13 ; CHECK-NEXT: [[TMP4:%.*]] = sub <4 x i64> [[TMP1]], [[TMP3]]
14 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x i64> [[TMP4]], i32 0
15 ; CHECK-NEXT: [[GETELEMENTPTR_RES_1:%.*]] = getelementptr i32, ptr [[BASE_GEP]], i64 [[TMP5]]
16 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i64> [[TMP4]], i32 1
17 ; CHECK-NEXT: [[GETELEMENTPTR_RES_2:%.*]] = getelementptr i32, ptr [[BASE_GEP]], i64 [[TMP6]]
18 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i64> [[TMP4]], i32 2
19 ; CHECK-NEXT: [[GETELEMENTPTR_RES_3:%.*]] = getelementptr i32, ptr [[BASE_GEP]], i64 [[TMP7]]
20 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <4 x i64> [[TMP4]], i32 3
21 ; CHECK-NEXT: [[GETELEMENTPTR_RES_4:%.*]] = getelementptr i32, ptr [[BASE_GEP]], i64 [[TMP8]]
22 ; CHECK-NEXT: call void @use_4(ptr [[GETELEMENTPTR_RES_1]], ptr [[GETELEMENTPTR_RES_2]], ptr [[GETELEMENTPTR_RES_3]], ptr [[GETELEMENTPTR_RES_4]])
23 ; CHECK-NEXT: ret void
26 %load1 = load i32, ptr %base1, align 2
27 %zext1 = zext i32 %load1 to i64
28 %load2 = load i32, ptr %base2, align 2
29 %zext2 = zext i32 %load2 to i64
30 %sub = sub i64 %zext1, %zext2
31 %getelementptr.res.1 = getelementptr i32, ptr %base_gep, i64 %sub
32 %getelementptr1 = getelementptr i32, ptr %base1, i64 1
33 %getelementptr2 = getelementptr i32, ptr %base2, i64 1
34 %load3 = load i32, ptr %getelementptr1, align 2
35 %zext3 = zext i32 %load3 to i64
36 %load4 = load i32, ptr %getelementptr2, align 2
37 %zext4= zext i32 %load4 to i64
38 %sub2 = sub i64 %zext3, %zext4
39 %getelementptr.res.2 = getelementptr i32, ptr %base_gep, i64 %sub2
40 %getelementptr3 = getelementptr i32, ptr %base1, i64 2
41 %getelementptr4 = getelementptr i32, ptr %base2, i64 2
42 %load5 = load i32, ptr %getelementptr3, align 2
43 %zext5 = zext i32 %load5 to i64
44 %load6 = load i32, ptr %getelementptr4, align 2
45 %zext6 = zext i32 %load6 to i64
46 %sub3 = sub i64 %zext5, %zext6
47 %getelementptr.res.3 = getelementptr i32, ptr %base_gep, i64 %sub3
48 %getelementptr5 = getelementptr i32, ptr %base1, i64 3
49 %getelementptr6 = getelementptr i32, ptr %base2, i64 3
50 %load7 = load i32, ptr %getelementptr5, align 2
51 %zext7 = zext i32 %load7 to i64
52 %load8 = load i32, ptr %getelementptr6, align 2
53 %zext8 = zext i32 %load8 to i64
54 %sub4 = sub i64 %zext7, %zext8
55 %getelementptr.res.4 = getelementptr i32, ptr %base_gep, i64 %sub4
56 call void @use_4(ptr %getelementptr.res.1, ptr %getelementptr.res.2, ptr %getelementptr.res.3, ptr %getelementptr.res.4)
60 declare void @use_4(ptr, ptr, ptr, ptr)