@@ -1776,12 +1776,13 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
1776
1776
}
1777
1777
1778
1778
bool VectorCombine::scalarizeExtExtract (Instruction &I) {
1779
- if (!match (&I, m_ZExt (m_Value ())))
1779
+ auto *Ext = dyn_cast<ZExtInst>(&I);
1780
+ if (!Ext)
1780
1781
return false ;
1781
1782
1782
- // Try to convert a vector zext feeding only extracts to a set of scalar (Src
1783
- // << ExtIdx *Size) & (Size -1), if profitable.
1784
- auto *Ext = cast<ZExtInst>(&I);
1783
+ // Try to convert a vector zext feeding only extracts to a set of scalar
1784
+ // (Src << ExtIdx *Size) & (Size -1)
1785
+ // if profitable .
1785
1786
auto *SrcTy = dyn_cast<FixedVectorType>(Ext->getOperand (0 )->getType ());
1786
1787
if (!SrcTy)
1787
1788
return false ;
@@ -1822,21 +1823,20 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
1822
1823
return false ;
1823
1824
1824
1825
Value *ScalarV = Ext->getOperand (0 );
1825
- if (!isGuaranteedNotToBePoison (ScalarV, &AC))
1826
+ if (!isGuaranteedNotToBePoison (ScalarV, &AC, dyn_cast<Instruction>(ScalarV),
1827
+ &DT))
1826
1828
ScalarV = Builder.CreateFreeze (ScalarV);
1827
1829
ScalarV = Builder.CreateBitCast (
1828
1830
ScalarV,
1829
1831
IntegerType::get (SrcTy->getContext (), DL->getTypeSizeInBits (SrcTy)));
1830
1832
unsigned SrcEltSizeInBits = DL->getTypeSizeInBits (SrcTy->getElementType ());
1831
- Value *EltBitMask =
1832
- ConstantInt::get (ScalarV->getType (), (1ull << SrcEltSizeInBits) - 1 );
1833
- for (auto *U : to_vector (Ext->users ())) {
1833
+ unsigned EltBitMask = (1ull << SrcEltSizeInBits) - 1 ;
1834
+ for (User *U : Ext->users ()) {
1834
1835
auto *Extract = cast<ExtractElementInst>(U);
1835
- unsigned Idx =
1836
+ uint64_t Idx =
1836
1837
cast<ConstantInt>(Extract->getIndexOperand ())->getZExtValue ();
1837
- auto *S = Builder.CreateLShr (
1838
- ScalarV, ConstantInt::get (ScalarV->getType (), Idx * SrcEltSizeInBits));
1839
- auto *A = Builder.CreateAnd (S, EltBitMask);
1838
+ Value *S = Builder.CreateLShr (ScalarV, Idx * SrcEltSizeInBits);
1839
+ Value *A = Builder.CreateAnd (S, EltBitMask);
1840
1840
U->replaceAllUsesWith (A);
1841
1841
}
1842
1842
return true ;
0 commit comments