@@ -1859,6 +1859,39 @@ class ShuffleVectorInst : public Instruction {
1859
1859
1860
1860
SmallVector<int , 4 > ShuffleMask;
1861
1861
Constant *ShuffleMaskForBitcode;
1862
+ struct ShuffleProperties {
1863
+ bool isSingleSource : 1 ;
1864
+ bool isSingleSource_set : 1 ;
1865
+ bool isIdentityMask : 1 ;
1866
+ bool isIdentityMask_set : 1 ;
1867
+ bool isIdentityWithPadding : 1 ;
1868
+ bool isIdentityWithPadding_set : 1 ;
1869
+ bool isIdentityWithExtract : 1 ;
1870
+ bool isIdentityWithExtract_set : 1 ;
1871
+ bool isConcat : 1 ;
1872
+ bool isConcat_set : 1 ;
1873
+ bool isSelect : 1 ;
1874
+ bool isSelect_set : 1 ;
1875
+ bool isReverse : 1 ;
1876
+ bool isReverse_set : 1 ;
1877
+ bool isZeroEltSplat : 1 ;
1878
+ bool isZeroEltSplat_set : 1 ;
1879
+ bool isTranspose : 1 ;
1880
+ bool isTranspose_set : 1 ;
1881
+
1882
+ void unset () {
1883
+ isSingleSource_set = false ;
1884
+ isIdentityMask_set = false ;
1885
+ isIdentityWithPadding_set = false ;
1886
+ isIdentityWithExtract_set = false ;
1887
+ isConcat_set = false ;
1888
+ isSelect_set = false ;
1889
+ isReverse_set = false ;
1890
+ isZeroEltSplat_set = false ;
1891
+ isTranspose_set = false ;
1892
+ }
1893
+ };
1894
+ mutable ShuffleProperties CachedShuffleProperties = {};
1862
1895
1863
1896
protected:
1864
1897
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -1970,8 +2003,13 @@ class ShuffleVectorInst : public Instruction {
1970
2003
// / Example: shufflevector <4 x n> A, <4 x n> B, <3,0,undef,3>
1971
2004
// / TODO: Optionally allow length-changing shuffles.
1972
2005
bool isSingleSource () const {
1973
- return !changesLength () &&
1974
- isSingleSourceMask (ShuffleMask, ShuffleMask.size ());
2006
+ if (CachedShuffleProperties.isSingleSource_set )
2007
+ return CachedShuffleProperties.isSingleSource ;
2008
+
2009
+ CachedShuffleProperties.isSingleSource_set = true ;
2010
+ return CachedShuffleProperties.isSingleSource =
2011
+ !changesLength () &&
2012
+ isSingleSourceMask (ShuffleMask, ShuffleMask.size ());
1975
2013
}
1976
2014
1977
2015
// / Return true if this shuffle mask chooses elements from exactly one source
@@ -1998,12 +2036,18 @@ class ShuffleVectorInst : public Instruction {
1998
2036
// / from its input vectors.
1999
2037
// / Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
2000
2038
bool isIdentity () const {
2039
+ if (CachedShuffleProperties.isIdentityMask_set )
2040
+ return CachedShuffleProperties.isIdentityMask ;
2041
+
2042
+ CachedShuffleProperties.isIdentityMask_set = true ;
2001
2043
// Not possible to express a shuffle mask for a scalable vector for this
2002
2044
// case.
2003
2045
if (isa<ScalableVectorType>(getType ()))
2004
- return false ;
2046
+ return CachedShuffleProperties. isIdentityMask = false ;
2005
2047
2006
- return !changesLength () && isIdentityMask (ShuffleMask, ShuffleMask.size ());
2048
+ return CachedShuffleProperties.isIdentityMask =
2049
+ !changesLength () &&
2050
+ isIdentityMask (ShuffleMask, ShuffleMask.size ());
2007
2051
}
2008
2052
2009
2053
// / Return true if this shuffle lengthens exactly one source vector with
@@ -2044,7 +2088,13 @@ class ShuffleVectorInst : public Instruction {
2044
2088
// / In that case, the shuffle is better classified as an identity shuffle.
2045
2089
// / TODO: Optionally allow length-changing shuffles.
2046
2090
bool isSelect () const {
2047
- return !changesLength () && isSelectMask (ShuffleMask, ShuffleMask.size ());
2091
+ if (CachedShuffleProperties.isSelect_set )
2092
+ return CachedShuffleProperties.isSelect ;
2093
+
2094
+ CachedShuffleProperties.isSelect_set = true ;
2095
+ return CachedShuffleProperties.isSelect =
2096
+ !changesLength () &&
2097
+ isSelectMask (ShuffleMask, ShuffleMask.size ());
2048
2098
}
2049
2099
2050
2100
// / Return true if this shuffle mask swaps the order of elements from exactly
@@ -2065,7 +2115,13 @@ class ShuffleVectorInst : public Instruction {
2065
2115
// / Example: shufflevector <4 x n> A, <4 x n> B, <3,undef,1,undef>
2066
2116
// / TODO: Optionally allow length-changing shuffles.
2067
2117
bool isReverse () const {
2068
- return !changesLength () && isReverseMask (ShuffleMask, ShuffleMask.size ());
2118
+ if (CachedShuffleProperties.isReverse_set )
2119
+ return CachedShuffleProperties.isReverse ;
2120
+
2121
+ CachedShuffleProperties.isReverse_set = true ;
2122
+ return CachedShuffleProperties.isReverse =
2123
+ !changesLength () &&
2124
+ isReverseMask (ShuffleMask, ShuffleMask.size ());
2069
2125
}
2070
2126
2071
2127
// / Return true if this shuffle mask chooses all elements with the same value
@@ -2088,8 +2144,13 @@ class ShuffleVectorInst : public Instruction {
2088
2144
// / TODO: Optionally allow length-changing shuffles.
2089
2145
// / TODO: Optionally allow splats from other elements.
2090
2146
bool isZeroEltSplat () const {
2091
- return !changesLength () &&
2092
- isZeroEltSplatMask (ShuffleMask, ShuffleMask.size ());
2147
+ if (CachedShuffleProperties.isZeroEltSplat_set )
2148
+ return CachedShuffleProperties.isZeroEltSplat ;
2149
+
2150
+ CachedShuffleProperties.isZeroEltSplat_set = true ;
2151
+ return CachedShuffleProperties.isZeroEltSplat =
2152
+ !changesLength () &&
2153
+ isZeroEltSplatMask (ShuffleMask, ShuffleMask.size ());
2093
2154
}
2094
2155
2095
2156
// / Return true if this shuffle mask is a transpose mask.
@@ -2138,7 +2199,13 @@ class ShuffleVectorInst : public Instruction {
2138
2199
// / exact specification.
2139
2200
// / Example: shufflevector <4 x n> A, <4 x n> B, <0,4,2,6>
2140
2201
bool isTranspose () const {
2141
- return !changesLength () && isTransposeMask (ShuffleMask, ShuffleMask.size ());
2202
+ if (CachedShuffleProperties.isTranspose_set )
2203
+ return CachedShuffleProperties.isTranspose ;
2204
+
2205
+ CachedShuffleProperties.isTranspose_set = true ;
2206
+ return CachedShuffleProperties.isTranspose =
2207
+ !changesLength () &&
2208
+ isTransposeMask (ShuffleMask, ShuffleMask.size ());
2142
2209
}
2143
2210
2144
2211
// / Return true if this shuffle mask is a splice mask, concatenating the two
0 commit comments