1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; llvm.experimental.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.experimental.vector.extract.v10i32.v8i32(<8 x i32> %vec, i64 %idx)
8 declare <2 x i32> @llvm.experimental.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 %idx)
9 declare <3 x i32> @llvm.experimental.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 %idx)
10 declare <4 x i32> @llvm.experimental.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 %idx)
11 declare <4 x i32> @llvm.experimental.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 %idx)
12 declare <8 x i32> @llvm.experimental.vector.extract.v8i32.v8i32(<8 x i32> %vec, i64 %idx)
14 ; ============================================================================ ;
16 ; ============================================================================ ;
18 ; Extracting the entirety of a vector is a nop.
19 define <8 x i32> @trivial_nop(<8 x i32> %vec) {
20 ; CHECK-LABEL: @trivial_nop(
21 ; CHECK-NEXT: ret <8 x i32> [[VEC:%.*]]
23 %1 = call <8 x i32> @llvm.experimental.vector.extract.v8i32.v8i32(<8 x i32> %vec, i64 0)
27 ; ============================================================================ ;
28 ; Valid canonicalizations
29 ; ============================================================================ ;
31 define <2 x i32> @valid_extraction_a(<8 x i32> %vec) {
32 ; CHECK-LABEL: @valid_extraction_a(
33 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 0, i32 1>
34 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
36 %1 = call <2 x i32> @llvm.experimental.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 0)
40 define <2 x i32> @valid_extraction_b(<8 x i32> %vec) {
41 ; CHECK-LABEL: @valid_extraction_b(
42 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 2, i32 3>
43 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
45 %1 = call <2 x i32> @llvm.experimental.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 2)
49 define <2 x i32> @valid_extraction_c(<8 x i32> %vec) {
50 ; CHECK-LABEL: @valid_extraction_c(
51 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 4, i32 5>
52 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
54 %1 = call <2 x i32> @llvm.experimental.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 4)
58 define <2 x i32> @valid_extraction_d(<8 x i32> %vec) {
59 ; CHECK-LABEL: @valid_extraction_d(
60 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <2 x i32> <i32 6, i32 7>
61 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
63 %1 = call <2 x i32> @llvm.experimental.vector.extract.v2i32.v4i32(<8 x i32> %vec, i64 6)
67 define <4 x i32> @valid_extraction_e(<8 x i32> %vec) {
68 ; CHECK-LABEL: @valid_extraction_e(
69 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
70 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
72 %1 = call <4 x i32> @llvm.experimental.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 0)
76 define <4 x i32> @valid_extraction_f(<8 x i32> %vec) {
77 ; CHECK-LABEL: @valid_extraction_f(
78 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
79 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
81 %1 = call <4 x i32> @llvm.experimental.vector.extract.v4i32.v8i32(<8 x i32> %vec, i64 4)
85 define <3 x i32> @valid_extraction_g(<8 x i32> %vec) {
86 ; CHECK-LABEL: @valid_extraction_g(
87 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <3 x i32> <i32 0, i32 1, i32 2>
88 ; CHECK-NEXT: ret <3 x i32> [[TMP1]]
90 %1 = call <3 x i32> @llvm.experimental.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 0)
94 define <3 x i32> @valid_extraction_h(<8 x i32> %vec) {
95 ; CHECK-LABEL: @valid_extraction_h(
96 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[VEC:%.*]], <8 x i32> poison, <3 x i32> <i32 3, i32 4, i32 5>
97 ; CHECK-NEXT: ret <3 x i32> [[TMP1]]
99 %1 = call <3 x i32> @llvm.experimental.vector.extract.v3i32.v8i32(<8 x i32> %vec, i64 3)
103 ; ============================================================================ ;
105 ; ============================================================================ ;
107 ; Scalable extractions should not be canonicalized. This will be lowered to the
108 ; EXTRACT_SUBVECTOR ISD node later.
109 define <4 x i32> @scalable_extract(<vscale x 4 x i32> %vec) {
110 ; CHECK-LABEL: @scalable_extract(
111 ; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.experimental.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> [[VEC:%.*]], i64 0)
112 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
114 %1 = call <4 x i32> @llvm.experimental.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 0)