Skip to content

Commit 94abecc

Browse files
committed
[IVDescriptors] Remove typed pointer support (NFC)
This also removes the element type from the descriptor, as it is always i8. The meaning of the step is now the same between integers and pointers.
1 parent e705b2b commit 94abecc

File tree

3 files changed

+7
-59
lines changed

3 files changed

+7
-59
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class InductionDescriptor {
309309
enum InductionKind {
310310
IK_NoInduction, ///< Not an induction variable.
311311
IK_IntInduction, ///< Integer induction variable. Step = C.
312-
IK_PtrInduction, ///< Pointer induction var. Step = C / sizeof(elem).
312+
IK_PtrInduction, ///< Pointer induction var. Step = C.
313313
IK_FpInduction ///< Floating point induction variable.
314314
};
315315

@@ -369,11 +369,6 @@ class InductionDescriptor {
369369
: Instruction::BinaryOpsEnd;
370370
}
371371

372-
Type *getElementType() const {
373-
assert(IK == IK_PtrInduction && "Only pointer induction has element type");
374-
return ElementType;
375-
}
376-
377372
/// Returns a reference to the type cast instructions in the induction
378373
/// update chain, that are redundant when guarded with a runtime
379374
/// SCEV overflow check.
@@ -385,7 +380,6 @@ class InductionDescriptor {
385380
/// Private constructor - used by \c isInductionPHI.
386381
InductionDescriptor(Value *Start, InductionKind K, const SCEV *Step,
387382
BinaryOperator *InductionBinOp = nullptr,
388-
Type *ElementType = nullptr,
389383
SmallVectorImpl<Instruction *> *Casts = nullptr);
390384

391385
/// Start value.
@@ -396,9 +390,6 @@ class InductionDescriptor {
396390
const SCEV *Step = nullptr;
397391
// Instruction that advances induction variable.
398392
BinaryOperator *InductionBinOp = nullptr;
399-
// Element type for pointer induction variables.
400-
// TODO: This can be dropped once support for typed pointers is removed.
401-
Type *ElementType = nullptr;
402393
// Instructions used for type-casts of the induction variable,
403394
// that are redundant when guarded with a runtime SCEV overflow check.
404395
SmallVector<Instruction *, 2> RedundantCasts;

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,8 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
12361236

12371237
InductionDescriptor::InductionDescriptor(Value *Start, InductionKind K,
12381238
const SCEV *Step, BinaryOperator *BOp,
1239-
Type *ElementType,
12401239
SmallVectorImpl<Instruction *> *Casts)
1241-
: StartValue(Start), IK(K), Step(Step), InductionBinOp(BOp),
1242-
ElementType(ElementType) {
1240+
: StartValue(Start), IK(K), Step(Step), InductionBinOp(BOp) {
12431241
assert(IK != IK_NoInduction && "Not an induction");
12441242

12451243
// Start value type should match the induction kind and the value
@@ -1265,11 +1263,6 @@ InductionDescriptor::InductionDescriptor(Value *Start, InductionKind K,
12651263
InductionBinOp->getOpcode() == Instruction::FSub))) &&
12661264
"Binary opcode should be specified for FP induction");
12671265

1268-
if (IK == IK_PtrInduction)
1269-
assert(ElementType && "Pointer induction must have element type");
1270-
else
1271-
assert(!ElementType && "Non-pointer induction cannot have element type");
1272-
12731266
if (Casts) {
12741267
for (auto &Inst : *Casts) {
12751268
RedundantCasts.push_back(Inst);
@@ -1535,49 +1528,13 @@ bool InductionDescriptor::isInductionPHI(
15351528
BinaryOperator *BOp =
15361529
dyn_cast<BinaryOperator>(Phi->getIncomingValueForBlock(Latch));
15371530
D = InductionDescriptor(StartValue, IK_IntInduction, Step, BOp,
1538-
/* ElementType */ nullptr, CastsToIgnore);
1531+
CastsToIgnore);
15391532
return true;
15401533
}
15411534

15421535
assert(PhiTy->isPointerTy() && "The PHI must be a pointer");
1543-
PointerType *PtrTy = cast<PointerType>(PhiTy);
15441536

1545-
// Always use i8 element type for opaque pointer inductions.
15461537
// This allows induction variables w/non-constant steps.
1547-
if (PtrTy->isOpaque()) {
1548-
D = InductionDescriptor(StartValue, IK_PtrInduction, Step,
1549-
/* BinOp */ nullptr,
1550-
Type::getInt8Ty(PtrTy->getContext()));
1551-
return true;
1552-
}
1553-
1554-
// Pointer induction should be a constant.
1555-
// TODO: This could be generalized, but should probably just
1556-
// be dropped instead once the migration to opaque ptrs is
1557-
// complete.
1558-
if (!ConstStep)
1559-
return false;
1560-
1561-
Type *ElementType = PtrTy->getNonOpaquePointerElementType();
1562-
if (!ElementType->isSized())
1563-
return false;
1564-
1565-
ConstantInt *CV = ConstStep->getValue();
1566-
const DataLayout &DL = Phi->getModule()->getDataLayout();
1567-
TypeSize TySize = DL.getTypeAllocSize(ElementType);
1568-
// TODO: We could potentially support this for scalable vectors if we can
1569-
// prove at compile time that the constant step is always a multiple of
1570-
// the scalable type.
1571-
if (TySize.isZero() || TySize.isScalable())
1572-
return false;
1573-
1574-
int64_t Size = static_cast<int64_t>(TySize.getFixedValue());
1575-
int64_t CVSize = CV->getSExtValue();
1576-
if (CVSize % Size)
1577-
return false;
1578-
auto *StepValue =
1579-
SE->getConstant(CV->getType(), CVSize / Size, true /* signed */);
1580-
D = InductionDescriptor(StartValue, IK_PtrInduction, StepValue,
1581-
/* BinOp */ nullptr, ElementType);
1538+
D = InductionDescriptor(StartValue, IK_PtrInduction, Step);
15821539
return true;
15831540
}

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@ static Value *emitTransformedIndex(IRBuilderBase &B, Value *Index,
24582458
return CreateAdd(StartValue, Offset);
24592459
}
24602460
case InductionDescriptor::IK_PtrInduction: {
2461-
return B.CreateGEP(ID.getElementType(), StartValue, CreateMul(Index, Step));
2461+
return B.CreateGEP(B.getInt8Ty(), StartValue, CreateMul(Index, Step));
24622462
}
24632463
case InductionDescriptor::IK_FpInduction: {
24642464
assert(!isa<VectorType>(Index->getType()) &&
@@ -9473,7 +9473,7 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
94739473
Value *NumUnrolledElems =
94749474
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, State.UF));
94759475
Value *InductionGEP = GetElementPtrInst::Create(
9476-
IndDesc.getElementType(), NewPointerPhi,
9476+
State.Builder.getInt8Ty(), NewPointerPhi,
94779477
State.Builder.CreateMul(ScalarStepValue, NumUnrolledElems), "ptr.ind",
94789478
InductionLoc);
94799479
// Add induction update using an incorrect block temporarily. The phi node
@@ -9499,7 +9499,7 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
94999499
assert(ScalarStepValue == State.get(getOperand(1), VPIteration(Part, 0)) &&
95009500
"scalar step must be the same across all parts");
95019501
Value *GEP = State.Builder.CreateGEP(
9502-
IndDesc.getElementType(), NewPointerPhi,
9502+
State.Builder.getInt8Ty(), NewPointerPhi,
95039503
State.Builder.CreateMul(
95049504
StartOffset,
95059505
State.Builder.CreateVectorSplat(State.VF, ScalarStepValue),

0 commit comments

Comments
 (0)