@@ -1888,76 +1888,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1888
1888
1889
1889
constexpr int PoisonMaskElem = -1;
1890
1890
1891
- // / Attributes of a shufflevector mask.
1892
- struct ShuffleMaskAttrs {
1893
- // / If the shuffle chooses elements from exactly one source vector without
1894
- // / changing the length of that vector.
1895
- // / Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
1896
- // / TODO: Optionally allow length-changing shuffles.
1897
- bool SingleSource : 1 ;
1898
-
1899
- // / If the shuffle chooses elements from exactly one source vector without
1900
- // / lane crossings and does not change the number of elements from its input
1901
- // / vectors.
1902
- // / Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
1903
- bool Identity : 1 ;
1904
-
1905
- // / If the shuffle lengthens exactly one source vector with undefs in the
1906
- // / high elements.
1907
- bool IdentityWithPadding : 1 ;
1908
-
1909
- // / If the shuffle extracts the first N elements of exactly one source
1910
- // / vector.
1911
- bool IdentityWithExtract : 1 ;
1912
-
1913
- // / If the shuffle concatenates the two source vectors. This is false if
1914
- // / either input is undefined. In that case, the shuffle is better classified
1915
- // / as an identity with padding operation.
1916
- bool Concat : 1 ;
1917
-
1918
- // / If the shuffle swaps the order of elements from exactly one source vector.
1919
- // / Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
1920
- // / TODO: Optionally allow length-changing shuffles.
1921
- bool Reverse : 1 ;
1922
-
1923
- // / If all elements of the shuffle are the same value as the first element of
1924
- // / exactly one source vector without changing the length of that vector.
1925
- // / Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
1926
- // / TODO: Optionally allow length-changing shuffles.
1927
- // / TODO: Optionally allow splats from other elements.
1928
- bool ZeroEltSplat : 1 ;
1929
-
1930
- // / Return true if this shuffle chooses elements from its source vectors
1931
- // / without lane crossings and all operands have the same number of elements.
1932
- // / In other words, this shuffle is equivalent to a vector select with a
1933
- // / constant condition operand.
1934
- // / Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
1935
- // / This returns false if the mask does not choose from both input vectors.
1936
- // / In that case, the shuffle is better classified as an identity shuffle.
1937
- // / TODO: Optionally allow length-changing shuffles.
1938
- bool Select : 1 ;
1939
-
1940
- // / If the shuffle transposes the elements of its inputs without changing the
1941
- // / length of the vectors. This operation may also be known as a merge or
1942
- // / interleave. See the description for isTransposeMask() for the exact
1943
- // / specification.
1944
- // / Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
1945
- bool Transpose : 1 ;
1946
-
1947
- // / If the shuffle splices two inputs without changing the length of the
1948
- // / vectors. This operation concatenates the two inputs together and then
1949
- // / extracts an original width vector starting from the splice index.
1950
- // / Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
1951
- bool Splice : 1 ;
1952
-
1953
- // / The starting index of the splice.
1954
- // / Example: 1, from the previous example
1955
- int SpliceIndex;
1956
- };
1957
-
1958
- static_assert (sizeof (ShuffleMaskAttrs) <= sizeof(uint64_t ),
1959
- "ShuffleMaskAttrs is too large!");
1960
-
1961
1891
// / This instruction constructs a fixed permutation of two
1962
1892
// / input vectors.
1963
1893
// /
@@ -1973,7 +1903,6 @@ class ShuffleVectorInst : public Instruction {
1973
1903
1974
1904
SmallVector<int , 4 > ShuffleMask;
1975
1905
Constant *ShuffleMaskForBitcode;
1976
- ShuffleMaskAttrs MaskAttrs;
1977
1906
1978
1907
protected:
1979
1908
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -2000,12 +1929,6 @@ class ShuffleVectorInst : public Instruction {
2000
1929
// / of the instruction.
2001
1930
void commute ();
2002
1931
2003
- // Analyze mask of fixed vector. NumOpElts is number of known elements in
2004
- // operand1/operand2. Scalable is set if any operands are scalable vectors.
2005
- // HasUndefOp is set if there are any undef operands.
2006
- static ShuffleMaskAttrs analyzeMask (ArrayRef<int > Mask, int NumOpElts,
2007
- bool Scalable, bool HasUndefOp);
2008
-
2009
1932
// / Return true if a shufflevector instruction can be
2010
1933
// / formed with the specified operands.
2011
1934
static bool isValidOperands (const Value *V1, const Value *V2,
@@ -2086,7 +2009,14 @@ class ShuffleVectorInst : public Instruction {
2086
2009
return isSingleSourceMask (MaskAsInts, NumSrcElts);
2087
2010
}
2088
2011
2089
- bool isSingleSource () const { return MaskAttrs.SingleSource ; }
2012
+ // / Return true if this shuffle chooses elements from exactly one source
2013
+ // / vector without changing the length of that vector.
2014
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
2015
+ // / TODO: Optionally allow length-changing shuffles.
2016
+ bool isSingleSource () const {
2017
+ return !changesLength () &&
2018
+ isSingleSourceMask (ShuffleMask, ShuffleMask.size ());
2019
+ }
2090
2020
2091
2021
// / Return true if this shuffle mask chooses elements from exactly one source
2092
2022
// / vector without lane crossings. A shuffle using this mask is not
@@ -2107,13 +2037,31 @@ class ShuffleVectorInst : public Instruction {
2107
2037
return isIdentityMask (MaskAsInts, NumSrcElts);
2108
2038
}
2109
2039
2110
- bool isIdentity () const { return MaskAttrs.Identity ; }
2040
+ // / Return true if this shuffle chooses elements from exactly one source
2041
+ // / vector without lane crossings and does not change the number of elements
2042
+ // / from its input vectors.
2043
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
2044
+ bool isIdentity () const {
2045
+ // Not possible to express a shuffle mask for a scalable vector for this
2046
+ // case.
2047
+ if (isa<ScalableVectorType>(getType ()))
2048
+ return false ;
2049
+
2050
+ return !changesLength () && isIdentityMask (ShuffleMask, ShuffleMask.size ());
2051
+ }
2111
2052
2112
- bool isIdentityWithPadding () const { return MaskAttrs.IdentityWithPadding ; }
2053
+ // / Return true if this shuffle lengthens exactly one source vector with
2054
+ // / undefs in the high elements.
2055
+ bool isIdentityWithPadding () const ;
2113
2056
2114
- bool isIdentityWithExtract () const { return MaskAttrs.IdentityWithExtract ; }
2057
+ // / Return true if this shuffle extracts the first N elements of exactly one
2058
+ // / source vector.
2059
+ bool isIdentityWithExtract () const ;
2115
2060
2116
- bool isConcat () const { return MaskAttrs.Concat ; }
2061
+ // / Return true if this shuffle concatenates its 2 source vectors. This
2062
+ // / returns false if either input is undefined. In that case, the shuffle is
2063
+ // / is better classified as an identity with padding operation.
2064
+ bool isConcat () const ;
2117
2065
2118
2066
// / Return true if this shuffle mask chooses elements from its source vectors
2119
2067
// / without lane crossings. A shuffle using this mask would be
@@ -2131,7 +2079,17 @@ class ShuffleVectorInst : public Instruction {
2131
2079
return isSelectMask (MaskAsInts, NumSrcElts);
2132
2080
}
2133
2081
2134
- bool isSelect () const { return MaskAttrs.Select ; }
2082
+ // / Return true if this shuffle chooses elements from its source vectors
2083
+ // / without lane crossings and all operands have the same number of elements.
2084
+ // / In other words, this shuffle is equivalent to a vector select with a
2085
+ // / constant condition operand.
2086
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <undef,1,6,3>
2087
+ // / This returns false if the mask does not choose from both input vectors.
2088
+ // / In that case, the shuffle is better classified as an identity shuffle.
2089
+ // / TODO: Optionally allow length-changing shuffles.
2090
+ bool isSelect () const {
2091
+ return !changesLength () && isSelectMask (ShuffleMask, ShuffleMask.size ());
2092
+ }
2135
2093
2136
2094
// / Return true if this shuffle mask swaps the order of elements from exactly
2137
2095
// / one source vector.
@@ -2146,7 +2104,13 @@ class ShuffleVectorInst : public Instruction {
2146
2104
return isReverseMask (MaskAsInts, NumSrcElts);
2147
2105
}
2148
2106
2149
- bool isReverse () const { return MaskAttrs.Reverse ; }
2107
+ // / Return true if this shuffle swaps the order of elements from exactly
2108
+ // / one source vector.
2109
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
2110
+ // / TODO: Optionally allow length-changing shuffles.
2111
+ bool isReverse () const {
2112
+ return !changesLength () && isReverseMask (ShuffleMask, ShuffleMask.size ());
2113
+ }
2150
2114
2151
2115
// / Return true if this shuffle mask chooses all elements with the same value
2152
2116
// / as the first element of exactly one source vector.
@@ -2161,7 +2125,16 @@ class ShuffleVectorInst : public Instruction {
2161
2125
return isZeroEltSplatMask (MaskAsInts, NumSrcElts);
2162
2126
}
2163
2127
2164
- bool isZeroEltSplat () const { return MaskAttrs.ZeroEltSplat ; }
2128
+ // / Return true if all elements of this shuffle are the same value as the
2129
+ // / first element of exactly one source vector without changing the length
2130
+ // / of that vector.
2131
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <undef,0,undef,0>
2132
+ // / TODO: Optionally allow length-changing shuffles.
2133
+ // / TODO: Optionally allow splats from other elements.
2134
+ bool isZeroEltSplat () const {
2135
+ return !changesLength () &&
2136
+ isZeroEltSplatMask (ShuffleMask, ShuffleMask.size ());
2137
+ }
2165
2138
2166
2139
// / Return true if this shuffle mask is a transpose mask.
2167
2140
// / Transpose vector masks transpose a 2xn matrix. They read corresponding
@@ -2203,7 +2176,14 @@ class ShuffleVectorInst : public Instruction {
2203
2176
return isTransposeMask (MaskAsInts, NumSrcElts);
2204
2177
}
2205
2178
2206
- bool isTranspose () const { return MaskAttrs.Transpose ; }
2179
+ // / Return true if this shuffle transposes the elements of its inputs without
2180
+ // / changing the length of the vectors. This operation may also be known as a
2181
+ // / merge or interleave. See the description for isTransposeMask() for the
2182
+ // / exact specification.
2183
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
2184
+ bool isTranspose () const {
2185
+ return !changesLength () && isTransposeMask (ShuffleMask, ShuffleMask.size ());
2186
+ }
2207
2187
2208
2188
// / Return true if this shuffle mask is a splice mask, concatenating the two
2209
2189
// / inputs together and then extracts an original width vector starting from
@@ -2219,9 +2199,13 @@ class ShuffleVectorInst : public Instruction {
2219
2199
return isSpliceMask (MaskAsInts, NumSrcElts, Index);
2220
2200
}
2221
2201
2202
+ // / Return true if this shuffle splices two inputs without changing the length
2203
+ // / of the vectors. This operation concatenates the two inputs together and
2204
+ // / then extracts an original width vector starting from the splice index.
2205
+ // / Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2222
2206
bool isSplice (int &Index) const {
2223
- Index = MaskAttrs. SpliceIndex ;
2224
- return MaskAttrs. Splice ;
2207
+ return ! changesLength () &&
2208
+ isSpliceMask (ShuffleMask, ShuffleMask. size (), Index) ;
2225
2209
}
2226
2210
2227
2211
// / Return true if this shuffle mask is an extract subvector mask.
0 commit comments