@@ -157,7 +157,7 @@ using EqClassKey =
157157struct ChainElem {
158158 Instruction *Inst;
159159 APInt OffsetFromLeader;
160- bool Redundant = false ; // Set to true when load is redundant.
160+ unsigned IncrementalBytes;
161161 ChainElem (Instruction *Inst, APInt OffsetFromLeader)
162162 : Inst(std::move(Inst)), OffsetFromLeader(std::move(OffsetFromLeader)) {}
163163};
@@ -638,21 +638,23 @@ std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) {
638638
639639 // Add this instruction to the end of the current chain, or start a new one.
640640 APInt ReadEnd = It->OffsetFromLeader + SzBits / 8 ;
641- bool IsRedundant = ReadEnd.sle (PrevReadEnd);
642- bool AreContiguous = It->OffsetFromLeader == PrevReadEnd;
641+ unsigned ExtraBytes =
642+ PrevReadEnd.sle (ReadEnd) ? (ReadEnd - PrevReadEnd).getSExtValue () : 0u ;
643+ bool AreContiguous = It->OffsetFromLeader .sle (PrevReadEnd);
643644
644645 LLVM_DEBUG (dbgs () << " LSV: Instruction is "
645- << (AreContiguous
646- ? " contiguous"
647- : ((IsRedundant ? " redundant" : " chain-breaker" )))
646+ << (AreContiguous ? " contiguous" : " chain-breaker" )
648647 << *It->Inst << " (starts at offset "
649648 << It->OffsetFromLeader << " )\n " );
650649
651- It-> Redundant = IsRedundant;
652- if (AreContiguous || IsRedundant)
650+ if (AreContiguous) {
651+ It-> IncrementalBytes = ExtraBytes;
653652 CurChain.push_back (*It);
654- else
653+ }
654+ else {
655+ It->IncrementalBytes = SzBits / 8 ;
655656 Ret.push_back ({*It});
657+ }
656658 PrevReadEnd = APIntOps::smax (PrevReadEnd, ReadEnd);
657659 }
658660
@@ -883,11 +885,9 @@ bool Vectorizer::vectorizeChain(Chain &C) {
883885 bool IsLoadChain = isa<LoadInst>(C[0 ].Inst );
884886 unsigned AS = getLoadStoreAddressSpace (C[0 ].Inst );
885887 unsigned ChainBytes = 0 ;
886- for (auto &E : C) {
887- if (E.Redundant )
888- continue ;
889- ChainBytes += DL.getTypeStoreSize (getLoadStoreType (E.Inst ));
890- }
888+ for (auto &E : C)
889+ ChainBytes += E.IncrementalBytes ;
890+
891891 assert (ChainBytes % DL.getTypeStoreSize (VecElemTy) == 0 );
892892 // VecTy is a power of 2 and 1 byte at smallest, but VecElemTy may be smaller
893893 // than 1 byte (e.g. VecTy == <32 x i1>).
0 commit comments