Debian Codegraph @

llvm-project/llvm/unittests/IR/ShuffleVectorInstTest.cpp

raw
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 //===----------------------------------------------------------------------===//
8
9 #include "llvm/IR/Instructions.h"
10 #include "gtest/gtest.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 TEST(ShuffleVectorInst, isIdentityMask) {
17 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3}));
18 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 3, -1}));
19 ASSERT_TRUE(ShuffleVectorInst::isIdentityMask({0, 1, -1, 3}));
20
21 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, 1, 2, 4}));
22 ASSERT_FALSE(ShuffleVectorInst::isIdentityMask({0, -1, 2, 4}));
23 }
24
25 TEST(ShuffleVectorInst, isSelectMask) {
26 ASSERT_TRUE(ShuffleVectorInst::isSelectMask({0, 5, 6, 3}));
27
28 ASSERT_FALSE(ShuffleVectorInst::isSelectMask({0, 1, 2, 3}));
29 }
30
31 TEST(ShuffleVectorInst, isReverseMask) {
32 ASSERT_TRUE(ShuffleVectorInst::isReverseMask({3, 2, 1, 0}));
33 ASSERT_TRUE(ShuffleVectorInst::isReverseMask({-1, -1, 1, 0}));
34
35 ASSERT_FALSE(ShuffleVectorInst::isReverseMask({4, 3, 2, 1}));
36 }
37
38 TEST(ShuffleVectorInst, isZeroEltSplatMask) {
39 ASSERT_TRUE(ShuffleVectorInst::isZeroEltSplatMask({0, 0, 0, 0}));
40 ASSERT_TRUE(ShuffleVectorInst::isZeroEltSplatMask({0, -1, 0, -1}));
41
42 ASSERT_FALSE(ShuffleVectorInst::isZeroEltSplatMask({1, 1, 1, 1}));
43 }
44
45 TEST(ShuffleVectorInst, isTransposeMask) {
46 ASSERT_TRUE(ShuffleVectorInst::isTransposeMask({0, 4, 2, 6}));
47 ASSERT_TRUE(ShuffleVectorInst::isTransposeMask({1, 5, 3, 7}));
48
49 ASSERT_FALSE(ShuffleVectorInst::isTransposeMask({2, 6, 4, 8}));
50 }
51
52 TEST(ShuffleVectorInst, isSpliceMask) {
53 int Index;
54
55 ASSERT_TRUE(ShuffleVectorInst::isSpliceMask({0, 1, 2, 3}, Index));
56 ASSERT_EQ(0, Index);
57
58 ASSERT_TRUE(ShuffleVectorInst::isSpliceMask({1, 2, 3, 4, 5, 6, 7}, Index));
59 ASSERT_EQ(1, Index);
60
61 ASSERT_FALSE(ShuffleVectorInst::isSpliceMask({4, 5, 6, 7}, Index));
62 }
63
64 TEST(ShuffleVectorInst, isExtractSubvectorMask) {
65 int Index;
66
67 ASSERT_TRUE(
68 ShuffleVectorInst::isExtractSubvectorMask({0, 1, 2, 3}, 8, Index));
69 ASSERT_EQ(0, Index);
70
71 ASSERT_TRUE(
72 ShuffleVectorInst::isExtractSubvectorMask({-1, 3, 4, 5}, 8, Index));
73 ASSERT_EQ(2, Index);
74
75 ASSERT_FALSE(
76 ShuffleVectorInst::isExtractSubvectorMask({1, 2, 3, -1}, 4, Index));
77 }
78
79 TEST(ShuffleVectorInst, isInsertSubvectorMask) {
80 int NumSubElts, Index;
81
82 ASSERT_TRUE(ShuffleVectorInst::isInsertSubvectorMask(
83 {8, 9, 10, 11, 4, 5, 6, 7}, 8, NumSubElts, Index));
84 ASSERT_EQ(0, Index);
85 ASSERT_EQ(4, NumSubElts);
86
87 ASSERT_TRUE(
88 ShuffleVectorInst::isInsertSubvectorMask({0, 2}, 2, NumSubElts, Index));
89 ASSERT_EQ(1, Index);
90 ASSERT_EQ(1, NumSubElts);
91 }
92
93 TEST(ShuffleVectorInst, isReplicationMask) {
94 int ReplicationFactor, VF;
95
96 ASSERT_TRUE(ShuffleVectorInst::isReplicationMask({0, 0, 1, 1, 2, 2, 3, 3},
97 ReplicationFactor, VF));
98 ASSERT_EQ(2, ReplicationFactor);
99 ASSERT_EQ(4, VF);
100
101 ASSERT_TRUE(ShuffleVectorInst::isReplicationMask(
102 {0, 0, 0, 1, 1, 1, -1, -1, -1, 3, 3, 3, 4, 4, 4}, ReplicationFactor, VF));
103 ASSERT_EQ(3, ReplicationFactor);
104 ASSERT_EQ(5, VF);
105 }
106
107 TEST(ShuffleVectorInst, isOneUseSingleSourceMask) {
108 ASSERT_TRUE(
109 ShuffleVectorInst::isOneUseSingleSourceMask({0, 1, 2, 3, 3, 2, 0, 1}, 4));
110 ASSERT_TRUE(
111 ShuffleVectorInst::isOneUseSingleSourceMask({2, 3, 4, 5, 6, 7, 0, 1}, 8));
112
113 ASSERT_FALSE(ShuffleVectorInst::isOneUseSingleSourceMask(
114 {0, -1, 2, 3, 3, 2, 0, 1}, 4));
115 ASSERT_FALSE(
116 ShuffleVectorInst::isOneUseSingleSourceMask({0, 1, 2, 3, 3, 3, 1, 0}, 4));
117 }
118
119 } // end anonymous namespace