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