Skip to content

Commit 4666be3

Browse files
committed
Revert "[Instructions] cache computed shufflevector properties"
This reverts commit 24a39050595b7f32e7374f67d281d91bfd3cf303.
1 parent 4a0ab38 commit 4666be3

File tree

2 files changed

+132
-197
lines changed

2 files changed

+132
-197
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 72 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,76 +1888,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
18881888

18891889
constexpr int PoisonMaskElem = -1;
18901890

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-
19611891
/// This instruction constructs a fixed permutation of two
19621892
/// input vectors.
19631893
///
@@ -1973,7 +1903,6 @@ class ShuffleVectorInst : public Instruction {
19731903

19741904
SmallVector<int, 4> ShuffleMask;
19751905
Constant *ShuffleMaskForBitcode;
1976-
ShuffleMaskAttrs MaskAttrs;
19771906

19781907
protected:
19791908
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -2000,12 +1929,6 @@ class ShuffleVectorInst : public Instruction {
20001929
/// of the instruction.
20011930
void commute();
20021931

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-
20091932
/// Return true if a shufflevector instruction can be
20101933
/// formed with the specified operands.
20111934
static bool isValidOperands(const Value *V1, const Value *V2,
@@ -2086,7 +2009,14 @@ class ShuffleVectorInst : public Instruction {
20862009
return isSingleSourceMask(MaskAsInts, NumSrcElts);
20872010
}
20882011

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+
}
20902020

20912021
/// Return true if this shuffle mask chooses elements from exactly one source
20922022
/// vector without lane crossings. A shuffle using this mask is not
@@ -2107,13 +2037,31 @@ class ShuffleVectorInst : public Instruction {
21072037
return isIdentityMask(MaskAsInts, NumSrcElts);
21082038
}
21092039

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+
}
21112052

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;
21132056

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;
21152060

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;
21172065

21182066
/// Return true if this shuffle mask chooses elements from its source vectors
21192067
/// without lane crossings. A shuffle using this mask would be
@@ -2131,7 +2079,17 @@ class ShuffleVectorInst : public Instruction {
21312079
return isSelectMask(MaskAsInts, NumSrcElts);
21322080
}
21332081

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+
}
21352093

21362094
/// Return true if this shuffle mask swaps the order of elements from exactly
21372095
/// one source vector.
@@ -2146,7 +2104,13 @@ class ShuffleVectorInst : public Instruction {
21462104
return isReverseMask(MaskAsInts, NumSrcElts);
21472105
}
21482106

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+
}
21502114

21512115
/// Return true if this shuffle mask chooses all elements with the same value
21522116
/// as the first element of exactly one source vector.
@@ -2161,7 +2125,16 @@ class ShuffleVectorInst : public Instruction {
21612125
return isZeroEltSplatMask(MaskAsInts, NumSrcElts);
21622126
}
21632127

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+
}
21652138

21662139
/// Return true if this shuffle mask is a transpose mask.
21672140
/// Transpose vector masks transpose a 2xn matrix. They read corresponding
@@ -2203,7 +2176,14 @@ class ShuffleVectorInst : public Instruction {
22032176
return isTransposeMask(MaskAsInts, NumSrcElts);
22042177
}
22052178

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+
}
22072187

22082188
/// Return true if this shuffle mask is a splice mask, concatenating the two
22092189
/// inputs together and then extracts an original width vector starting from
@@ -2219,9 +2199,13 @@ class ShuffleVectorInst : public Instruction {
22192199
return isSpliceMask(MaskAsInts, NumSrcElts, Index);
22202200
}
22212201

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>
22222206
bool isSplice(int &Index) const {
2223-
Index = MaskAttrs.SpliceIndex;
2224-
return MaskAttrs.Splice;
2207+
return !changesLength() &&
2208+
isSpliceMask(ShuffleMask, ShuffleMask.size(), Index);
22252209
}
22262210

22272211
/// Return true if this shuffle mask is an extract subvector mask.

0 commit comments

Comments
 (0)