Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class LoopVectorizationLegality {
RecurrenceSet &getFixedOrderRecurrences() { return FixedOrderRecurrences; }

/// Returns the widest induction type.
Type *getWidestInductionType() { return WidestIndTy; }
IntegerType *getWidestInductionType() { return WidestIndTy; }

/// Returns True if given store is a final invariant store of one of the
/// reductions found in the loop.
Expand Down Expand Up @@ -595,7 +595,7 @@ class LoopVectorizationLegality {
RecurrenceSet FixedOrderRecurrences;

/// Holds the widest induction type encountered.
Type *WidestIndTy = nullptr;
IntegerType *WidestIndTy = nullptr;

/// Allowed outside users. This holds the variables that can be accessed from
/// outside the loop.
Expand Down
28 changes: 16 additions & 12 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,24 +395,25 @@ static bool isUniformLoopNest(Loop *Lp, Loop *OuterLp) {
return true;
}

static Type *convertPointerToIntegerType(const DataLayout &DL, Type *Ty) {
static IntegerType *getInductionIntegerTy(const DataLayout &DL, Type *Ty) {
assert(Ty->isIntOrPtrTy() && "Expected integer or pointer type");

if (Ty->isPointerTy())
return DL.getIntPtrType(Ty);
return DL.getIntPtrType(Ty->getContext(), Ty->getPointerAddressSpace());

// It is possible that char's or short's overflow when we ask for the loop's
// trip count, work around this by changing the type size.
if (Ty->getScalarSizeInBits() < 32)
return Type::getInt32Ty(Ty->getContext());

return Ty;
return cast<IntegerType>(Ty);
}

static Type *getWiderType(const DataLayout &DL, Type *Ty0, Type *Ty1) {
Ty0 = convertPointerToIntegerType(DL, Ty0);
Ty1 = convertPointerToIntegerType(DL, Ty1);
if (Ty0->getScalarSizeInBits() > Ty1->getScalarSizeInBits())
return Ty0;
return Ty1;
static IntegerType *getWiderInductionTy(const DataLayout &DL, Type *Ty0,
Type *Ty1) {
IntegerType *TyA = getInductionIntegerTy(DL, Ty0);
IntegerType *TyB = getInductionIntegerTy(DL, Ty1);
return (TyA->getScalarSizeInBits() > TyB->getScalarSizeInBits()) ? TyA : TyB;
}

/// Check that the instruction has outside loop users and is not an
Expand Down Expand Up @@ -692,12 +693,15 @@ void LoopVectorizationLegality::addInductionPhi(
Type *PhiTy = Phi->getType();
const DataLayout &DL = Phi->getDataLayout();

assert((PhiTy->isIntOrPtrTy() || PhiTy->isFloatingPointTy()) &&
"Expected int, ptr, or FP induction phi type");

// Get the widest type.
if (!PhiTy->isFloatingPointTy()) {
if (PhiTy->isIntOrPtrTy()) {
if (!WidestIndTy)
WidestIndTy = convertPointerToIntegerType(DL, PhiTy);
WidestIndTy = getInductionIntegerTy(DL, PhiTy);
else
WidestIndTy = getWiderType(DL, PhiTy, WidestIndTy);
WidestIndTy = getWiderInductionTy(DL, PhiTy, WidestIndTy);
}

// Int inductions are special because we only allow one IV.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,8 +2353,8 @@ static bool isIndvarOverflowCheckKnownFalse(
// Always be conservative if we don't know the exact unroll factor.
unsigned MaxUF = UF ? *UF : Cost->TTI.getMaxInterleaveFactor(VF);

Type *IdxTy = Cost->Legal->getWidestInductionType();
APInt MaxUIntTripCount = cast<IntegerType>(IdxTy)->getMask();
IntegerType *IdxTy = Cost->Legal->getWidestInductionType();
APInt MaxUIntTripCount = IdxTy->getMask();

// We know the runtime overflow check is known false iff the (max) trip-count
// is known and (max) trip-count + (VF * UF) does not overflow in the type of
Expand Down
Loading