1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine %s -S | FileCheck %s
3 ; RUN: opt -passes=instcombine -use-constant-int-for-fixed-length-splat %s -S | FileCheck %s
5 define ptr @vector_splat_indices_v2i64_ext0(ptr %a) {
6 ; CHECK-LABEL: @vector_splat_indices_v2i64_ext0(
7 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 16
8 ; CHECK-NEXT: ret ptr [[RES]]
10 %gep = getelementptr i32, ptr %a, <2 x i64> <i64 4, i64 4>
11 %res = extractelement <2 x ptr> %gep, i32 0
15 define ptr @vector_splat_indices_nxv2i64_ext0(ptr %a) {
16 ; CHECK-LABEL: @vector_splat_indices_nxv2i64_ext0(
17 ; CHECK-NEXT: [[RES:%.*]] = getelementptr inbounds nuw i8, ptr [[A:%.*]], i64 16
18 ; CHECK-NEXT: ret ptr [[RES]]
20 %tmp = insertelement <vscale x 2 x i64> poison, i64 4, i32 0
21 %splatof4 = shufflevector <vscale x 2 x i64> %tmp, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
22 %gep = getelementptr inbounds i32, ptr %a, <vscale x 2 x i64> %splatof4
23 %res = extractelement <vscale x 2 x ptr> %gep, i32 0
27 define ptr @vector_indices_v2i64_ext0(ptr %a, <2 x i64> %indices) {
28 ; CHECK-LABEL: @vector_indices_v2i64_ext0(
29 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i64> [[INDICES:%.*]], i64 0
30 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i32, ptr [[A:%.*]], i64 [[TMP1]]
31 ; CHECK-NEXT: ret ptr [[RES]]
33 %gep = getelementptr i32, ptr %a, <2 x i64> %indices
34 %res = extractelement <2 x ptr> %gep, i32 0
38 define ptr @vector_indices_nxv1i64_ext0(ptr %a, <vscale x 1 x i64> %indices) {
39 ; CHECK-LABEL: @vector_indices_nxv1i64_ext0(
40 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <vscale x 1 x i64> [[INDICES:%.*]], i64 0
41 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i32, ptr [[A:%.*]], i64 [[TMP1]]
42 ; CHECK-NEXT: ret ptr [[RES]]
44 %gep = getelementptr i32, ptr %a, <vscale x 1 x i64> %indices
45 %res = extractelement <vscale x 1 x ptr> %gep, i32 0
50 define ptr @vector_splat_ptrs_v2i64_ext0(ptr %a, i64 %index) {
51 ; CHECK-LABEL: @vector_splat_ptrs_v2i64_ext0(
52 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i32, ptr [[A:%.*]], i64 [[INDEX:%.*]]
53 ; CHECK-NEXT: ret ptr [[RES]]
55 %tmp = insertelement <2 x ptr> poison, ptr %a, i32 0
56 %splatofa = shufflevector <2 x ptr> %tmp, <2 x ptr> poison, <2 x i32> zeroinitializer
57 %gep = getelementptr i32, <2 x ptr> %splatofa, i64 %index
58 %res = extractelement <2 x ptr> %gep, i32 0
63 define ptr @vector_splat_ptrs_nxv2i64_ext0(ptr %a, i64 %index) {
64 ; CHECK-LABEL: @vector_splat_ptrs_nxv2i64_ext0(
65 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i32, ptr [[A:%.*]], i64 [[INDEX:%.*]]
66 ; CHECK-NEXT: ret ptr [[RES]]
68 %tmp = insertelement <vscale x 2 x ptr> poison, ptr %a, i32 0
69 %splatofa = shufflevector <vscale x 2 x ptr> %tmp, <vscale x 2 x ptr> poison, <vscale x 2 x i32> zeroinitializer
70 %gep = getelementptr i32, <vscale x 2 x ptr> %splatofa, i64 %index
71 %res = extractelement <vscale x 2 x ptr> %gep, i32 0
76 define ptr @vector_struct1_splat_indices_v4i64_ext1(ptr %a) {
77 ; CHECK-LABEL: @vector_struct1_splat_indices_v4i64_ext1(
78 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 32
79 ; CHECK-NEXT: ret ptr [[RES]]
81 %gep = getelementptr {float, float}, ptr %a, <4 x i32> <i32 4, i32 4, i32 4, i32 4>, i32 0
82 %res = extractelement <4 x ptr> %gep, i32 1
87 define ptr @vector_struct2_splat_indices_v4i64_ext1(ptr %a) {
88 ; CHECK-LABEL: @vector_struct2_splat_indices_v4i64_ext1(
89 ; CHECK-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 92
90 ; CHECK-NEXT: ret ptr [[RES]]
92 %gep = getelementptr {float, [8 x float]}, ptr %a, i32 2, i32 1, <4 x i32> <i32 4, i32 4, i32 4, i32 4>
93 %res = extractelement <4 x ptr> %gep, i32 1
100 define ptr @vector_indices_nxv2i64_ext3(ptr %a, <vscale x 2 x i64> %indices) {
101 ; CHECK-LABEL: @vector_indices_nxv2i64_ext3(
102 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[A:%.*]], <vscale x 2 x i64> [[INDICES:%.*]]
103 ; CHECK-NEXT: [[RES:%.*]] = extractelement <vscale x 2 x ptr> [[GEP]], i64 3
104 ; CHECK-NEXT: ret ptr [[RES]]
106 %gep = getelementptr i32, ptr %a, <vscale x 2 x i64> %indices
107 %res = extractelement <vscale x 2 x ptr> %gep, i32 3
111 define ptr @vector_indices_nxv2i64_extN(ptr %a, <vscale x 2 x i64> %indices, i32 %N) {
112 ; CHECK-LABEL: @vector_indices_nxv2i64_extN(
113 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[A:%.*]], <vscale x 2 x i64> [[INDICES:%.*]]
114 ; CHECK-NEXT: [[RES:%.*]] = extractelement <vscale x 2 x ptr> [[GEP]], i32 [[N:%.*]]
115 ; CHECK-NEXT: ret ptr [[RES]]
117 %gep = getelementptr i32, ptr %a, <vscale x 2 x i64> %indices
118 %res = extractelement <vscale x 2 x ptr> %gep, i32 %N
122 define void @vector_indices_nxv2i64_mulitple_use(ptr %a, <vscale x 2 x i64> %indices, ptr %b, ptr %c) {
123 ; CHECK-LABEL: @vector_indices_nxv2i64_mulitple_use(
124 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[A:%.*]], <vscale x 2 x i64> [[INDICES:%.*]]
125 ; CHECK-NEXT: [[LANE0:%.*]] = extractelement <vscale x 2 x ptr> [[GEP]], i64 0
126 ; CHECK-NEXT: [[LANE1:%.*]] = extractelement <vscale x 2 x ptr> [[GEP]], i64 1
127 ; CHECK-NEXT: store ptr [[LANE0]], ptr [[B:%.*]], align 8
128 ; CHECK-NEXT: store ptr [[LANE1]], ptr [[C:%.*]], align 8
129 ; CHECK-NEXT: ret void
131 %gep = getelementptr i32, ptr %a, <vscale x 2 x i64> %indices
132 %lane0 = extractelement <vscale x 2 x ptr> %gep, i32 0
133 %lane1 = extractelement <vscale x 2 x ptr> %gep, i32 1
134 store ptr %lane0, ptr %b, align 8
135 store ptr %lane1, ptr %c, align 8
139 define ptr @vector_ptrs_and_indices_ext0(<vscale x 4 x ptr> %a, <vscale x 4 x i64> %indices) {
140 ; CHECK-LABEL: @vector_ptrs_and_indices_ext0(
141 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <vscale x 4 x ptr> [[A:%.*]], <vscale x 4 x i64> [[INDICES:%.*]]
142 ; CHECK-NEXT: [[RES:%.*]] = extractelement <vscale x 4 x ptr> [[GEP]], i64 0
143 ; CHECK-NEXT: ret ptr [[RES]]
145 %gep = getelementptr i32, <vscale x 4 x ptr> %a, <vscale x 4 x i64> %indices
146 %res = extractelement <vscale x 4 x ptr> %gep, i32 0