1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; llvm.vector.extract canonicalizes to shufflevector in the fixed case. In the
5 ; scalable case, we lower to the EXTRACT_SUBVECTOR ISD node.
7 declare <10 x i32> @llvm.vector.extract.v10i32.v8i32(<8 x i32> %vec, i64 %idx)
8 declare <2 x i32> @llvm.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 %idx)
9 declare <3 x i32> @llvm.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 %idx)
10 declare <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 %idx)
11 declare <4 x i32> @llvm.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 %idx)
12 declare <8 x i32> @llvm.vector.extract.v8i32.v8i32(<8 x i32> %vec, i64 %idx)
13 declare <vscale x 8 x i32> @llvm.vector.extract.nxv8i32.nxv8i32(<vscale x 8 x i32> %vec, i64 %idx)
15 ; ============================================================================ ;
17 ; ============================================================================ ;
19 ; Extracting the entirety of a vector is a nop.
20 define <8 x i32> @trivial_nop(<8 x i32> %vec) {
21 ; CHECK-LABEL: @trivial_nop(
22 ; CHECK-NEXT: ret <8 x i32> [[VEC:%.*]]
24 %1 = call <8 x i32> @llvm.vector.extract.v8i32.v8i32(<8 x i32> %vec, i64 0)
28 define <vscale x 8 x i32> @trivial_nop_scalable(<vscale x 8 x i32> %vec) {
29 ; CHECK-LABEL: define <vscale x 8 x i32> @trivial_nop_scalable(
30 ; CHECK-SAME: <vscale x 8 x i32> [[VEC:%.*]]) {
31 ; CHECK-NEXT: ret <vscale x 8 x i32> [[VEC]]
33 %ext = call <vscale x 8 x i32> @llvm.vector.extract.nxv8i32.nxv8i32(<vscale x 8 x i32> %vec, i64 0)
34 ret <vscale x 8 x i32> %ext
37 ; ============================================================================ ;
38 ; Valid canonicalizations
39 ; ============================================================================ ;
41 define <2 x i32> @valid_extraction_a(<8 x i32> %vec) {
42 ; CHECK-LABEL: @valid_extraction_a(
43 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 0, i32 1>
44 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
46 %1 = call <2 x i32> @llvm.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 0)
50 define <2 x i32> @valid_extraction_b(<8 x i32> %vec) {
51 ; CHECK-LABEL: @valid_extraction_b(
52 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 2, i32 3>
53 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
55 %1 = call <2 x i32> @llvm.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 2)
59 define <2 x i32> @valid_extraction_c(<8 x i32> %vec) {
60 ; CHECK-LABEL: @valid_extraction_c(
61 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 4, i32 5>
62 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
64 %1 = call <2 x i32> @llvm.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 4)
68 define <2 x i32> @valid_extraction_d(<8 x i32> %vec) {
69 ; CHECK-LABEL: @valid_extraction_d(
70 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 6, i32 7>
71 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
73 %1 = call <2 x i32> @llvm.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 6)
77 define <4 x i32> @valid_extraction_e(<8 x i32> %vec) {
78 ; CHECK-LABEL: @valid_extraction_e(
79 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
80 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
82 %1 = call <4 x i32> @llvm.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 0)
86 define <4 x i32> @valid_extraction_f(<8 x i32> %vec) {
87 ; CHECK-LABEL: @valid_extraction_f(
88 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
89 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
91 %1 = call <4 x i32> @llvm.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 4)
95 define <3 x i32> @valid_extraction_g(<8 x i32> %vec) {
96 ; CHECK-LABEL: @valid_extraction_g(
97 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <3 x i32> <i32 0, i32 1, i32 2>
98 ; CHECK-NEXT: ret <3 x i32> [[TMP1]]
100 %1 = call <3 x i32> @llvm.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 0)
104 define <3 x i32> @valid_extraction_h(<8 x i32> %vec) {
105 ; CHECK-LABEL: @valid_extraction_h(
106 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <3 x i32> <i32 3, i32 4, i32 5>
107 ; CHECK-NEXT: ret <3 x i32> [[TMP1]]
109 %1 = call <3 x i32> @llvm.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 3)
113 ; ============================================================================ ;
115 ; ============================================================================ ;
117 ; Scalable extractions should not be canonicalized. This will be lowered to the
118 ; EXTRACT_SUBVECTOR ISD node later.
119 define <4 x i32> @scalable_extract(<vscale x 4 x i32> %vec) {
120 ; CHECK-LABEL: @scalable_extract(
121 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> [[VEC:%.*]], i64 0)
122 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
124 %1 = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 0)