Skip to content

Commit e69482f

Browse files
committed
[IR] Fix GEP offset computations for vector GEPs
Vectors are always bit-packed and don't respect the elements' alignment requirements. This is different from arrays. This means offsets of GEPs into vectors need to be computed differently than array GEPs. This patch fixes many places by replacing a common-but-incorrect pattern that always relies on DL.getTypeAllocSize() by GTI.getSequentialElementStride(DL). This changes behavior for GEPs into vectors with element types that have a (bit) size and alloc size. This includes two cases: * Types with a bit size that is not a multiple of a byte, e.g. i1. GEPs into such vectors are questionable to begin with, as some elements are not even addressable. * Overaligned types, e.g. i16 with 32-bit alignment. Existing tests are unaffected, except for one precommitted test that is no longer miscompiled.
1 parent 2e80e58 commit e69482f

27 files changed

+45
-55
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5292,8 +5292,8 @@ static GEPOffsetAndOverflow EmitGEPOffsetInBytes(Value *BasePtr, Value *GEPVal,
52925292
} else {
52935293
// Otherwise this is array-like indexing. The local offset is the index
52945294
// multiplied by the element size.
5295-
auto *ElementSize = llvm::ConstantInt::get(
5296-
IntPtrTy, DL.getTypeAllocSize(GTI.getIndexedType()));
5295+
auto *ElementSize =
5296+
llvm::ConstantInt::get(IntPtrTy, GTI.getSequentialElementStride(DL));
52975297
auto *IndexS = Builder.CreateIntCast(Index, IntPtrTy, /*isSigned=*/true);
52985298
LocalOffset = eval(BO_Mul, ElementSize, IndexS);
52995299
}

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
10411041
if (TargetType->isScalableTy())
10421042
return TTI::TCC_Basic;
10431043
int64_t ElementSize =
1044-
DL.getTypeAllocSize(GTI.getIndexedType()).getFixedValue();
1044+
GTI.getSequentialElementStride(DL).getFixedValue();
10451045
if (ConstIdx) {
10461046
BaseOffset +=
10471047
ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
639639
continue;
640640

641641
// Don't attempt to analyze GEPs if the scalable index is not zero.
642-
TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
642+
TypeSize AllocTypeSize = GTI.getSequentialElementStride(DL);
643643
if (AllocTypeSize.isScalable()) {
644644
Decomposed.Base = V;
645645
return Decomposed;
@@ -650,7 +650,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
650650
continue;
651651
}
652652

653-
TypeSize AllocTypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
653+
TypeSize AllocTypeSize = GTI.getSequentialElementStride(DL);
654654
if (AllocTypeSize.isScalable()) {
655655
Decomposed.Base = V;
656656
return Decomposed;

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ bool CallAnalyzer::accumulateGEPOffset(GEPOperator &GEP, APInt &Offset) {
14291429
continue;
14301430
}
14311431

1432-
APInt TypeSize(IntPtrWidth, DL.getTypeAllocSize(GTI.getIndexedType()));
1432+
APInt TypeSize(IntPtrWidth, GTI.getSequentialElementStride(DL));
14331433
Offset += OpC->getValue().sextOrTrunc(IntPtrWidth) * TypeSize;
14341434
}
14351435
return true;

llvm/lib/Analysis/Local.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Value *llvm::emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL,
6464
// Convert to correct type.
6565
if (Op->getType() != IntIdxTy)
6666
Op = Builder->CreateIntCast(Op, IntIdxTy, true, Op->getName() + ".c");
67-
TypeSize TSize = DL.getTypeAllocSize(GTI.getIndexedType());
67+
TypeSize TSize = GTI.getSequentialElementStride(DL);
6868
if (TSize != TypeSize::getFixed(1)) {
6969
Value *Scale = Builder->CreateTypeSize(IntIdxTy->getScalarType(), TSize);
7070
if (IntIdxTy->isVectorTy())

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,10 @@ static unsigned getGEPInductionOperand(const GetElementPtrInst *Gep) {
27032703

27042704
// If it's a type with the same allocation size as the result of the GEP we
27052705
// can peel off the zero index.
2706-
if (DL.getTypeAllocSize(GEPTI.getIndexedType()) != GEPAllocSize)
2706+
TypeSize ElemSize = GEPTI.isStruct()
2707+
? DL.getTypeAllocSize(GEPTI.getIndexedType())
2708+
: GEPTI.getSequentialElementStride(DL);
2709+
if (ElemSize != GEPAllocSize)
27072710
break;
27082711
--LastOperand;
27092712
}

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
12301230
unsigned IndexBitWidth = Index->getType()->getScalarSizeInBits();
12311231
KnownBits IndexBits(IndexBitWidth);
12321232
computeKnownBits(Index, IndexBits, Depth + 1, Q);
1233-
TypeSize IndexTypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1233+
TypeSize IndexTypeSize = GTI.getSequentialElementStride(Q.DL);
12341234
uint64_t TypeSizeInBytes = IndexTypeSize.getKnownMinValue();
12351235
KnownBits ScalingFactor(IndexBitWidth);
12361236
// Multiply by current sizeof type.
@@ -2158,7 +2158,7 @@ static bool isGEPKnownNonNull(const GEPOperator *GEP, unsigned Depth,
21582158
}
21592159

21602160
// If we have a zero-sized type, the index doesn't matter. Keep looping.
2161-
if (Q.DL.getTypeAllocSize(GTI.getIndexedType()).isZero())
2161+
if (GTI.getSequentialElementStride(Q.DL).isZero())
21622162
continue;
21632163

21642164
// Fast path the constant operand case both for efficiency and so we don't

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4787,7 +4787,7 @@ bool AddressingModeMatcher::matchOperationAddr(User *AddrInst, unsigned Opcode,
47874787
cast<ConstantInt>(AddrInst->getOperand(i))->getZExtValue();
47884788
ConstantOffset += SL->getElementOffset(Idx);
47894789
} else {
4790-
TypeSize TS = DL.getTypeAllocSize(GTI.getIndexedType());
4790+
TypeSize TS = GTI.getSequentialElementStride(DL);
47914791
if (TS.isNonZero()) {
47924792
// The optimisations below currently only work for fixed offsets.
47934793
if (TS.isScalable())

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ bool IRTranslator::translateGetElementPtr(const User &U,
15451545
Offset += DL->getStructLayout(StTy)->getElementOffset(Field);
15461546
continue;
15471547
} else {
1548-
uint64_t ElementSize = DL->getTypeAllocSize(GTI.getIndexedType());
1548+
uint64_t ElementSize = GTI.getSequentialElementStride(*DL);
15491549

15501550
// If this is a scalar constant or a splat vector of constants,
15511551
// handle it quickly.

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,13 @@ bool FastISel::selectGetElementPtr(const User *I) {
560560
}
561561
}
562562
} else {
563-
Type *Ty = GTI.getIndexedType();
564-
565563
// If this is a constant subscript, handle it quickly.
566564
if (const auto *CI = dyn_cast<ConstantInt>(Idx)) {
567565
if (CI->isZero())
568566
continue;
569567
// N = N + Offset
570568
uint64_t IdxN = CI->getValue().sextOrTrunc(64).getSExtValue();
571-
TotalOffs += DL.getTypeAllocSize(Ty) * IdxN;
569+
TotalOffs += GTI.getSequentialElementStride(DL) * IdxN;
572570
if (TotalOffs >= MaxOffs) {
573571
N = fastEmit_ri_(VT, ISD::ADD, N, TotalOffs, VT);
574572
if (!N) // Unhandled operand. Halt "fast" selection and bail.
@@ -585,7 +583,7 @@ bool FastISel::selectGetElementPtr(const User *I) {
585583
}
586584

587585
// N = N + Idx * ElementSize;
588-
uint64_t ElementSize = DL.getTypeAllocSize(Ty);
586+
uint64_t ElementSize = GTI.getSequentialElementStride(DL);
589587
Register IdxN = getRegForGEPIndex(Idx);
590588
if (!IdxN) // Unhandled operand. Halt "fast" selection and bail.
591589
return false;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4112,7 +4112,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
41124112
unsigned IdxSize = DAG.getDataLayout().getIndexSizeInBits(AS);
41134113
MVT IdxTy = MVT::getIntegerVT(IdxSize);
41144114
TypeSize ElementSize =
4115-
DAG.getDataLayout().getTypeAllocSize(GTI.getIndexedType());
4115+
GTI.getSequentialElementStride(DAG.getDataLayout());
41164116
// We intentionally mask away the high bits here; ElementSize may not
41174117
// fit in IdxTy.
41184118
APInt ElementMul(IdxSize, ElementSize.getKnownMinValue());

llvm/lib/ExecutionEngine/Interpreter/Execution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
10741074
assert(BitWidth == 64 && "Invalid index type for getelementptr");
10751075
Idx = (int64_t)IdxGV.IntVal.getZExtValue();
10761076
}
1077-
Total += getDataLayout().getTypeAllocSize(I.getIndexedType()) * Idx;
1077+
Total += I.getSequentialElementStride(getDataLayout()) * Idx;
10781078
}
10791079
}
10801080

llvm/lib/IR/DataLayout.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,8 @@ int64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
936936
// Add in the offset, as calculated by the structure layout info...
937937
Result += Layout->getElementOffset(FieldNo);
938938
} else {
939-
// Get the array index and the size of each array element.
940-
if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
941-
Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType());
939+
if (int64_t ArrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
940+
Result += ArrayIdx * GTI.getSequentialElementStride(*this);
942941
}
943942
}
944943

llvm/lib/IR/Operator.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Align GEPOperator::getMaxPreservedAlignment(const DataLayout &DL) const {
8787
/// If the index isn't known, we take 1 because it is the index that will
8888
/// give the worse alignment of the offset.
8989
const uint64_t ElemCount = OpC ? OpC->getZExtValue() : 1;
90-
Offset = DL.getTypeAllocSize(GTI.getIndexedType()) * ElemCount;
90+
Offset = GTI.getSequentialElementStride(DL) * ElemCount;
9191
}
9292
Result = Align(MinAlign(Offset, Result.value()));
9393
}
@@ -157,7 +157,7 @@ bool GEPOperator::accumulateConstantOffset(
157157
continue;
158158
}
159159
if (!AccumulateOffset(ConstOffset->getValue(),
160-
DL.getTypeAllocSize(GTI.getIndexedType())))
160+
GTI.getSequentialElementStride(DL)))
161161
return false;
162162
continue;
163163
}
@@ -170,8 +170,7 @@ bool GEPOperator::accumulateConstantOffset(
170170
if (!ExternalAnalysis(*V, AnalysisIndex))
171171
return false;
172172
UsedExternalAnalysis = true;
173-
if (!AccumulateOffset(AnalysisIndex,
174-
DL.getTypeAllocSize(GTI.getIndexedType())))
173+
if (!AccumulateOffset(AnalysisIndex, GTI.getSequentialElementStride(DL)))
175174
return false;
176175
}
177176
return true;
@@ -218,14 +217,13 @@ bool GEPOperator::collectOffset(
218217
continue;
219218
}
220219
CollectConstantOffset(ConstOffset->getValue(),
221-
DL.getTypeAllocSize(GTI.getIndexedType()));
220+
GTI.getSequentialElementStride(DL));
222221
continue;
223222
}
224223

225224
if (STy || ScalableType)
226225
return false;
227-
APInt IndexedSize =
228-
APInt(BitWidth, DL.getTypeAllocSize(GTI.getIndexedType()));
226+
APInt IndexedSize = APInt(BitWidth, GTI.getSequentialElementStride(DL));
229227
// Insert an initial offset of 0 for V iff none exists already, then
230228
// increment the offset by IndexedSize.
231229
if (!IndexedSize.isZero()) {

llvm/lib/IR/Value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) {
10151015

10161016
// Otherwise, we have a sequential type like an array or fixed-length
10171017
// vector. Multiply the index by the ElementSize.
1018-
TypeSize Size = DL.getTypeAllocSize(GTI.getIndexedType());
1018+
TypeSize Size = GTI.getSequentialElementStride(DL);
10191019
if (Size.isScalable())
10201020
return std::nullopt;
10211021
Offset += Size.getFixedValue() * OpC->getSExtValue();

llvm/lib/Target/AArch64/AArch64FastISel.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ bool AArch64FastISel::computeAddress(const Value *Obj, Address &Addr, Type *Ty)
645645
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
646646
TmpOffset += SL->getElementOffset(Idx);
647647
} else {
648-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
648+
uint64_t S = GTI.getSequentialElementStride(DL);
649649
while (true) {
650650
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
651651
// Constant-offset addressing.
@@ -4987,15 +4987,13 @@ bool AArch64FastISel::selectGetElementPtr(const Instruction *I) {
49874987
if (Field)
49884988
TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field);
49894989
} else {
4990-
Type *Ty = GTI.getIndexedType();
4991-
49924990
// If this is a constant subscript, handle it quickly.
49934991
if (const auto *CI = dyn_cast<ConstantInt>(Idx)) {
49944992
if (CI->isZero())
49954993
continue;
49964994
// N = N + Offset
4997-
TotalOffs +=
4998-
DL.getTypeAllocSize(Ty) * cast<ConstantInt>(CI)->getSExtValue();
4995+
TotalOffs += GTI.getSequentialElementStride(DL) *
4996+
cast<ConstantInt>(CI)->getSExtValue();
49994997
continue;
50004998
}
50014999
if (TotalOffs) {
@@ -5006,7 +5004,7 @@ bool AArch64FastISel::selectGetElementPtr(const Instruction *I) {
50065004
}
50075005

50085006
// N = N + Idx * ElementSize;
5009-
uint64_t ElementSize = DL.getTypeAllocSize(Ty);
5007+
uint64_t ElementSize = GTI.getSequentialElementStride(DL);
50105008
unsigned IdxN = getRegForGEPIndex(Idx);
50115009
if (!IdxN)
50125010
return false;

llvm/lib/Target/ARM/ARMFastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
747747
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
748748
TmpOffset += SL->getElementOffset(Idx);
749749
} else {
750-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
750+
uint64_t S = GTI.getSequentialElementStride(DL);
751751
while (true) {
752752
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
753753
// Constant-offset addressing.

llvm/lib/Target/Mips/MipsFastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ bool MipsFastISel::computeAddress(const Value *Obj, Address &Addr) {
492492
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
493493
TmpOffset += SL->getElementOffset(Idx);
494494
} else {
495-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
495+
uint64_t S = GTI.getSequentialElementStride(DL);
496496
while (true) {
497497
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
498498
// Constant-offset addressing.

llvm/lib/Target/PowerPC/PPCFastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ bool PPCFastISel::PPCComputeAddress(const Value *Obj, Address &Addr) {
350350
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
351351
TmpOffset += SL->getElementOffset(Idx);
352352
} else {
353-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
353+
uint64_t S = GTI.getSequentialElementStride(DL);
354354
for (;;) {
355355
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
356356
// Constant-offset addressing.

llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
362362

363363
VecOperand = i;
364364

365-
TypeSize TS = DL->getTypeAllocSize(GTI.getIndexedType());
365+
TypeSize TS = GTI.getSequentialElementStride(*DL);
366366
if (TS.isScalable())
367367
return std::make_pair(nullptr, nullptr);
368368

llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ bool WebAssemblyFastISel::computeAddress(const Value *Obj, Address &Addr) {
278278
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
279279
TmpOffset += SL->getElementOffset(Idx);
280280
} else {
281-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
281+
uint64_t S = GTI.getSequentialElementStride(DL);
282282
for (;;) {
283283
if (const auto *CI = dyn_cast<ConstantInt>(Op)) {
284284
// Constant-offset addressing.

llvm/lib/Target/X86/X86FastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) {
918918

919919
// A array/variable index is always of the form i*S where S is the
920920
// constant scale size. See if we can push the scale into immediates.
921-
uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
921+
uint64_t S = GTI.getSequentialElementStride(DL);
922922
for (;;) {
923923
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
924924
// Constant-offset addressing.

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,8 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
10971097
// For array or vector indices, scale the index by the size of the
10981098
// type.
10991099
APInt Index = OpC->getValue().sextOrTrunc(Offset.getBitWidth());
1100-
GEPOffset +=
1101-
Index *
1102-
APInt(Offset.getBitWidth(),
1103-
DL.getTypeAllocSize(GTI.getIndexedType()).getFixedValue());
1100+
GEPOffset += Index * APInt(Offset.getBitWidth(),
1101+
GTI.getSequentialElementStride(DL));
11041102
}
11051103

11061104
// If this index has computed an intermediate pointer which is not

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ SeparateConstOffsetFromGEP::accumulateByteOffset(GetElementPtrInst *GEP,
843843
// constant offset to a byte offset, and later offset the remainder of
844844
// the original GEP with this byte offset.
845845
AccumulativeByteOffset +=
846-
ConstantOffset * DL->getTypeAllocSize(GTI.getIndexedType());
846+
ConstantOffset * GTI.getSequentialElementStride(*DL);
847847
}
848848
} else if (LowerGEP) {
849849
StructType *StTy = GTI.getStructType();
@@ -884,7 +884,7 @@ void SeparateConstOffsetFromGEP::lowerToSingleIndexGEPs(
884884
continue;
885885

886886
APInt ElementSize = APInt(PtrIndexTy->getIntegerBitWidth(),
887-
DL->getTypeAllocSize(GTI.getIndexedType()));
887+
GTI.getSequentialElementStride(*DL));
888888
// Scale the index by element size.
889889
if (ElementSize != 1) {
890890
if (ElementSize.isPowerOf2()) {
@@ -946,7 +946,7 @@ SeparateConstOffsetFromGEP::lowerToArithmetics(GetElementPtrInst *Variadic,
946946
continue;
947947

948948
APInt ElementSize = APInt(IntPtrTy->getIntegerBitWidth(),
949-
DL->getTypeAllocSize(GTI.getIndexedType()));
949+
GTI.getSequentialElementStride(*DL));
950950
// Scale the index by element size.
951951
if (ElementSize != 1) {
952952
if (ElementSize.isPowerOf2()) {

llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
547547
// indices except this current one.
548548
const SCEV *BaseExpr = SE->getGEPExpr(cast<GEPOperator>(GEP), IndexExprs);
549549
Value *ArrayIdx = GEP->getOperand(I);
550-
uint64_t ElementSize = DL->getTypeAllocSize(GTI.getIndexedType());
550+
uint64_t ElementSize = GTI.getSequentialElementStride(*DL);
551551
if (ArrayIdx->getType()->getIntegerBitWidth() <=
552552
DL->getIndexSizeInBits(GEP->getAddressSpace())) {
553553
// Skip factoring if ArrayIdx is wider than the index size, because

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ std::optional<APInt> Vectorizer::getConstantOffsetComplexAddrs(
11931193
OpA->getType() != OpB->getType())
11941194
return std::nullopt;
11951195

1196-
uint64_t Stride = DL.getTypeAllocSize(GTIA.getIndexedType());
1196+
uint64_t Stride = GTIA.getSequentialElementStride(DL);
11971197

11981198
// Only look through a ZExt/SExt.
11991199
if (!isa<SExtInst>(OpA) && !isa<ZExtInst>(OpA))

llvm/test/Transforms/InstCombine/getelementptr.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ define void @test_evaluate_gep_as_ptrs_array(ptr addrspace(2) %B) {
114114
define void @test_overaligned_vec(i8 %B) {
115115
; This should be turned into a constexpr instead of being an instruction
116116
; CHECK-LABEL: @test_overaligned_vec(
117-
; TODO: In this test case, half is overaligned to 32 bits.
118-
; Vectors are bit-packed and don't respect alignment.
119-
; Thus, the byte offset of the second half in <2 x half> is 2 bytes, not 4 bytes:
120-
; CHECK-NEXT: store i8 [[B:%.*]], ptr getelementptr inbounds ([10 x i8], ptr @Global, i64 0, i64 4), align 1
117+
; CHECK-NEXT: store i8 [[B:%.*]], ptr getelementptr inbounds ([10 x i8], ptr @Global, i64 0, i64 2), align 1
121118
; CHECK-NEXT: ret void
122-
;
123119
%A = getelementptr <2 x half>, ptr @Global, i64 0, i64 1
124120
store i8 %B, ptr %A
125121
ret void

0 commit comments

Comments
 (0)