Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / IR / ShuffleVectorInstTest.cpp
blob5d840ec8d6720474786e7ace9b41ff42623f3339
1 //===- llvm/unittest/IR/ShuffleVectorInstTest.cpp - Shuffle unit tests ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/Instructions.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 TEST(ShuffleVectorInst, isIdentityMask) {
17 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3}, 4));
18 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3, -1}, 5));
19 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, -1, 3}, 4));
21 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3}, 3));
22 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3, -1}, 4));
23 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, -1, 3}, 3));
25 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3}, 5));
26 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3, -1}, 6));
27 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, -1, 3}, 5));
29 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 4}, 4));
30 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, -1, 2, 4}, 4));
33 TEST(ShuffleVectorInst, isSelectMask) {
34 ASSERT_TRUE(ShuffleVectorInst::isSelectMask({0, 5, 6, 3}, 4));
36 ASSERT_FALSE(ShuffleVectorInst::isSelectMask({0, 5, 6, 3}, 3));
37 ASSERT_FALSE(ShuffleVectorInst::isSelectMask({0, 5, 6, 3}, 5));
39 ASSERT_FALSE(ShuffleVectorInst::isSelectMask({0, 1, 2, 3}, 4));
42 TEST(ShuffleVectorInst, isReverseMask) {
43 ASSERT_TRUE(ShuffleVectorInst::isReverseMask({3, 2, 1, 0}, 4));
44 ASSERT_TRUE(ShuffleVectorInst::isReverseMask({-1, -1, 1, 0}, 4));
46 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({3, 2, 1, 0}, 3));
47 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({-1, -1, 1, 0}, 3));
48 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({3, 2, 1, 0}, 5));
49 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({-1, -1, 1, 0}, 5));
51 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({4, 3, 2, 1}, 4));
54 TEST(ShuffleVectorInst, isZeroEltSplatMask) {
55 ASSERT_TRUE(ShuffleVectorInst::isZeroEltSplatMask({0, 0, 0, 0}, 4));
56 ASSERT_TRUE(ShuffleVectorInst::isZeroEltSplatMask({0, -1, 0, -1}, 4));
58 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({0, 0, 0, 0}, 3));
59 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({0, -1, 0, -1}, 3));
60 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({0, 0, 0, 0}, 5));
61 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({0, -1, 0, -1}, 5));
63 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({1, 1, 1, 1}, 4));
66 TEST(ShuffleVectorInst, isTransposeMask) {
67 ASSERT_TRUE(ShuffleVectorInst::isTransposeMask({0, 4, 2, 6}, 4));
68 ASSERT_TRUE(ShuffleVectorInst::isTransposeMask({1, 5, 3, 7}, 4));
70 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({0, 4, 2, 6}, 3));
71 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({1, 5, 3, 7}, 3));
72 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({0, 4, 2, 6}, 5));
73 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({1, 5, 3, 7}, 5));
75 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({2, 6, 4, 8}, 4));
78 TEST(ShuffleVectorInst, isSpliceMask) {
79 int Index;
81 ASSERT_TRUE(ShuffleVectorInst::isSpliceMask({0, 1, 2, 3}, 4, Index));
82 ASSERT_EQ(0, Index);
84 ASSERT_TRUE(ShuffleVectorInst::isSpliceMask({1, 2, 3, 4, 5, 6, 7}, 7, Index));
85 ASSERT_EQ(1, Index);
87 ASSERT_FALSE(ShuffleVectorInst::isSpliceMask({0, 1, 2, 3}, 3, Index));
88 ASSERT_FALSE(
89 ShuffleVectorInst::isSpliceMask({1, 2, 3, 4, 5, 6, 7}, 6, Index));
90 ASSERT_FALSE(ShuffleVectorInst::isSpliceMask({0, 1, 2, 3}, 5, Index));
91 ASSERT_FALSE(
92 ShuffleVectorInst::isSpliceMask({1, 2, 3, 4, 5, 6, 7}, 8, Index));
94 ASSERT_FALSE(ShuffleVectorInst::isSpliceMask({4, 5, 6, 7}, 4, Index));
97 TEST(ShuffleVectorInst, isExtractSubvectorMask) {
98 int Index;
100 ASSERT_TRUE(
101 ShuffleVectorInst::isExtractSubvectorMask({0, 1, 2, 3}, 8, Index));
102 ASSERT_EQ(0, Index);
104 ASSERT_TRUE(
105 ShuffleVectorInst::isExtractSubvectorMask({-1, 3, 4, 5}, 8, Index));
106 ASSERT_EQ(2, Index);
108 ASSERT_FALSE(
109 ShuffleVectorInst::isExtractSubvectorMask({1, 2, 3, -1}, 4, Index));
112 TEST(ShuffleVectorInst, isInsertSubvectorMask) {
113 int NumSubElts, Index;
115 ASSERT_TRUE(ShuffleVectorInst::isInsertSubvectorMask(
116 {8, 9, 10, 11, 4, 5, 6, 7}, 8, NumSubElts, Index));
117 ASSERT_EQ(0, Index);
118 ASSERT_EQ(4, NumSubElts);
120 ASSERT_TRUE(
121 ShuffleVectorInst::isInsertSubvectorMask({0, 2}, 2, NumSubElts, Index));
122 ASSERT_EQ(1, Index);
123 ASSERT_EQ(1, NumSubElts);
126 TEST(ShuffleVectorInst, isReplicationMask) {
127 int ReplicationFactor, VF;
129 ASSERT_TRUE(ShuffleVectorInst::isReplicationMask({0, 0, 1, 1, 2, 2, 3, 3},
130 ReplicationFactor, VF));
131 ASSERT_EQ(2, ReplicationFactor);
132 ASSERT_EQ(4, VF);
134 ASSERT_TRUE(ShuffleVectorInst::isReplicationMask(
135 {0, 0, 0, 1, 1, 1, -1, -1, -1, 3, 3, 3, 4, 4, 4}, ReplicationFactor, VF));
136 ASSERT_EQ(3, ReplicationFactor);
137 ASSERT_EQ(5, VF);
140 TEST(ShuffleVectorInst, isOneUseSingleSourceMask) {
141 ASSERT_TRUE(
142 ShuffleVectorInst::isOneUseSingleSourceMask({0, 1, 2, 3, 3, 2, 0, 1}, 4));
143 ASSERT_TRUE(
144 ShuffleVectorInst::isOneUseSingleSourceMask({2, 3, 4, 5, 6, 7, 0, 1}, 8));
146 ASSERT_FALSE(ShuffleVectorInst::isOneUseSingleSourceMask(
147 {0, -1, 2, 3, 3, 2, 0, 1}, 4));
148 ASSERT_FALSE(
149 ShuffleVectorInst::isOneUseSingleSourceMask({0, 1, 2, 3, 3, 3, 1, 0}, 4));
152 TEST(ShuffleVectorInst, isInterleaveMask) {
153 SmallVector<unsigned> StartIndexes;
154 ASSERT_TRUE(ShuffleVectorInst::isInterleaveMask({0, 4, 1, 5, 2, 6, 3, 7}, 2,
155 8, StartIndexes));
156 ASSERT_EQ(StartIndexes, SmallVector<unsigned>({0, 4}));
158 ASSERT_FALSE(
159 ShuffleVectorInst::isInterleaveMask({0, 4, 1, 6, 2, 6, 3, 7}, 2, 8));
161 ASSERT_TRUE(ShuffleVectorInst::isInterleaveMask({4, 0, 5, 1, 6, 2, 7, 3}, 2,
162 8, StartIndexes));
163 ASSERT_EQ(StartIndexes, SmallVector<unsigned>({4, 0}));
165 ASSERT_TRUE(ShuffleVectorInst::isInterleaveMask({4, 0, -1, 1, -1, 2, 7, 3}, 2,
166 8, StartIndexes));
167 ASSERT_EQ(StartIndexes, SmallVector<unsigned>({4, 0}));
169 ASSERT_TRUE(ShuffleVectorInst::isInterleaveMask({0, 2, 4, 1, 3, 5}, 3, 6,
170 StartIndexes));
171 ASSERT_EQ(StartIndexes, SmallVector<unsigned>({0, 2, 4}));
173 ASSERT_TRUE(ShuffleVectorInst::isInterleaveMask({4, -1, 0, 5, 3, 1}, 3, 6,
174 StartIndexes));
175 ASSERT_EQ(StartIndexes, SmallVector<unsigned>({4, 2, 0}));
177 ASSERT_FALSE(
178 ShuffleVectorInst::isInterleaveMask({8, 2, 12, 4, 9, 3, 13, 5}, 4, 8));
181 } // end anonymous namespace