@@ -343,9 +343,6 @@ class Vectorizer {
343343 // / Postcondition: For all i, ret[i][0].second == 0, because the first instr
344344 // / in the chain is the leader, and an instr touches distance 0 from itself.
345345 std::vector<Chain> gatherChains (ArrayRef<Instruction *> Instrs);
346-
347- // / Propagates the best alignment in a chain of contiguous accesses
348- void propagateBestAlignmentInChain (ArrayRef<ChainElem> C) const ;
349346};
350347
351348class LoadStoreVectorizerLegacyPass : public FunctionPass {
@@ -719,14 +716,6 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
719716 unsigned AS = getLoadStoreAddressSpace (C[0 ].Inst );
720717 unsigned VecRegBytes = TTI.getLoadStoreVecRegBitWidth (AS) / 8 ;
721718
722- // We know that the accesses are contiguous. Propagate alignment
723- // information so that slices of the chain can still be vectorized.
724- propagateBestAlignmentInChain (C);
725- LLVM_DEBUG ({
726- dbgs () << " LSV: Chain after alignment propagation:\n " ;
727- dumpChain (C);
728- });
729-
730719 std::vector<Chain> Ret;
731720 for (unsigned CBegin = 0 ; CBegin < C.size (); ++CBegin) {
732721 // Find candidate chains of size not greater than the largest vector reg.
@@ -834,7 +823,6 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
834823 << Alignment.value () << " to " << NewAlign.value ()
835824 << " \n " );
836825 Alignment = NewAlign;
837- setLoadStoreAlignment (C[CBegin].Inst , Alignment);
838826 }
839827 }
840828
@@ -892,6 +880,14 @@ bool Vectorizer::vectorizeChain(Chain &C) {
892880 VecElemTy, 8 * ChainBytes / DL.getTypeSizeInBits (VecElemTy));
893881
894882 Align Alignment = getLoadStoreAlignment (C[0 ].Inst );
883+ // If this is a load/store of an alloca, we might have upgraded the alloca's
884+ // alignment earlier. Get the new alignment.
885+ if (AS == DL.getAllocaAddrSpace ()) {
886+ Alignment = std::max (
887+ Alignment,
888+ getOrEnforceKnownAlignment (getLoadStorePointerOperand (C[0 ].Inst ),
889+ MaybeAlign (), DL, C[0 ].Inst , nullptr , &DT));
890+ }
895891
896892 // All elements of the chain must have the same scalar-type size.
897893#ifndef NDEBUG
@@ -1638,24 +1634,3 @@ std::optional<APInt> Vectorizer::getConstantOffset(Value *PtrA, Value *PtrB,
16381634 .sextOrTrunc (OrigBitWidth);
16391635 return std::nullopt ;
16401636}
1641-
1642- void Vectorizer::propagateBestAlignmentInChain (ArrayRef<ChainElem> C) const {
1643- // Find the element in the chain with the best alignment and its offset.
1644- Align BestAlign = getLoadStoreAlignment (C[0 ].Inst );
1645- APInt BestAlignOffset = C[0 ].OffsetFromLeader ;
1646- for (const ChainElem &Elem : C) {
1647- Align ElemAlign = getLoadStoreAlignment (Elem.Inst );
1648- if (ElemAlign > BestAlign) {
1649- BestAlign = ElemAlign;
1650- BestAlignOffset = Elem.OffsetFromLeader ;
1651- }
1652- }
1653-
1654- // Propagate the best alignment to other elements in the chain, if possible.
1655- for (const ChainElem &Elem : C) {
1656- APInt OffsetDelta = APIntOps::abdu (Elem.OffsetFromLeader , BestAlignOffset);
1657- Align NewAlign = commonAlignment (BestAlign, OffsetDelta.getLimitedValue ());
1658- if (NewAlign > getLoadStoreAlignment (Elem.Inst ))
1659- setLoadStoreAlignment (Elem.Inst , NewAlign);
1660- }
1661- }
0 commit comments