Skip to content

Commit d696eee

Browse files
committed
Revert original solution
1 parent 8db304a commit d696eee

File tree

3 files changed

+9
-484
lines changed

3 files changed

+9
-484
lines changed

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

351348
class 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-
}

llvm/test/Transforms/LoadStoreVectorizer/X86/massive_indirection.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ define void @variadics1(ptr %vlist) {
155155
; CHECK-NEXT: [[ARGP_NEXT12:%.*]] = getelementptr i8, ptr [[ARGP_CUR11_ALIGNED]], i64 8
156156
; CHECK-NEXT: [[X2:%.*]] = getelementptr i8, ptr [[ARGP_NEXT12]], i32 7
157157
; CHECK-NEXT: [[ARGP_CUR16_ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[X2]], i64 0)
158-
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARGP_CUR16_ALIGNED]], align 8
158+
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARGP_CUR16_ALIGNED]], align 4294967296
159159
; CHECK-NEXT: [[X31:%.*]] = extractelement <2 x double> [[TMP1]], i32 0
160160
; CHECK-NEXT: [[X42:%.*]] = extractelement <2 x double> [[TMP1]], i32 1
161161
; CHECK-NEXT: [[X5:%.*]] = fadd double [[X42]], [[X31]]

0 commit comments

Comments
 (0)