Skip to content

Commit 2415636

Browse files
[SVE]Clarify TypeSize comparisons in llvm/lib/Transforms
Use isKnownXY comparators when one of the operands can be with scalable vectors or getFixedSize() for all the other cases. This patch also does bug fixes for getPrimitiveSizeInBits by using getFixedSize() near the places with the TypeSize comparison. Differential Revision: https://reviews.llvm.org/D89703
1 parent ffc0f57 commit 2415636

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,8 @@ static bool isPointerValueDeadOnEntryToFunction(
18801880
// and the number of bits loaded in L is less than or equal to
18811881
// the number of bits stored in S.
18821882
return DT.dominates(S, L) &&
1883-
DL.getTypeStoreSize(LTy) <= DL.getTypeStoreSize(STy);
1883+
DL.getTypeStoreSize(LTy).getFixedSize() <=
1884+
DL.getTypeStoreSize(STy).getFixedSize();
18841885
}))
18851886
return false;
18861887
}

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ InstCombinerImpl::foldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP,
314314
if (!GEP->isInBounds()) {
315315
Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
316316
unsigned PtrSize = IntPtrTy->getIntegerBitWidth();
317-
if (Idx->getType()->getPrimitiveSizeInBits() > PtrSize)
317+
if (Idx->getType()->getPrimitiveSizeInBits().getFixedSize() > PtrSize)
318318
Idx = Builder.CreateTrunc(Idx, IntPtrTy);
319319
}
320320

@@ -487,7 +487,8 @@ static Value *evaluateGEPOffsetExpression(User *GEP, InstCombinerImpl &IC,
487487
// Cast to intptrty in case a truncation occurs. If an extension is needed,
488488
// we don't need to bother extending: the extension won't affect where the
489489
// computation crosses zero.
490-
if (VariableIdx->getType()->getPrimitiveSizeInBits() > IntPtrWidth) {
490+
if (VariableIdx->getType()->getPrimitiveSizeInBits().getFixedSize() >
491+
IntPtrWidth) {
491492
VariableIdx = IC.Builder.CreateTrunc(VariableIdx, IntPtrTy);
492493
}
493494
return VariableIdx;
@@ -942,8 +943,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
942943
Type *LHSIndexTy = LOffset->getType();
943944
Type *RHSIndexTy = ROffset->getType();
944945
if (LHSIndexTy != RHSIndexTy) {
945-
if (LHSIndexTy->getPrimitiveSizeInBits() <
946-
RHSIndexTy->getPrimitiveSizeInBits()) {
946+
if (LHSIndexTy->getPrimitiveSizeInBits().getFixedSize() <
947+
RHSIndexTy->getPrimitiveSizeInBits().getFixedSize()) {
947948
ROffset = Builder.CreateTrunc(ROffset, LHSIndexTy);
948949
} else
949950
LOffset = Builder.CreateTrunc(LOffset, RHSIndexTy);

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,8 @@ static const SCEV *getNumBytes(const SCEV *BECount, Type *IntPtr,
896896
// If we're going to need to zero extend the BE count, check if we can add
897897
// one to it prior to zero extending without overflow. Provided this is safe,
898898
// it allows better simplification of the +1.
899-
if (DL->getTypeSizeInBits(BECount->getType()) <
900-
DL->getTypeSizeInBits(IntPtr) &&
899+
if (DL->getTypeSizeInBits(BECount->getType()).getFixedSize() <
900+
DL->getTypeSizeInBits(IntPtr).getFixedSize() &&
901901
SE->isLoopEntryGuardedByCond(
902902
CurLoop, ICmpInst::ICMP_NE, BECount,
903903
SE->getNegativeSCEV(SE->getOne(BECount->getType())))) {

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ static bool isSafeToTruncateWideIVType(const DataLayout &DL,
439439
Type *RangeCheckType) {
440440
if (!EnableIVTruncation)
441441
return false;
442-
assert(DL.getTypeSizeInBits(LatchCheck.IV->getType()) >
443-
DL.getTypeSizeInBits(RangeCheckType) &&
442+
assert(DL.getTypeSizeInBits(LatchCheck.IV->getType()).getFixedSize() >
443+
DL.getTypeSizeInBits(RangeCheckType).getFixedSize() &&
444444
"Expected latch check IV type to be larger than range check operand "
445445
"type!");
446446
// The start and end values of the IV should be known. This is to guarantee
@@ -460,7 +460,8 @@ static bool isSafeToTruncateWideIVType(const DataLayout &DL,
460460
// The active bits should be less than the bits in the RangeCheckType. This
461461
// guarantees that truncating the latch check to RangeCheckType is a safe
462462
// operation.
463-
auto RangeCheckTypeBitSize = DL.getTypeSizeInBits(RangeCheckType);
463+
auto RangeCheckTypeBitSize =
464+
DL.getTypeSizeInBits(RangeCheckType).getFixedSize();
464465
return Start->getAPInt().getActiveBits() < RangeCheckTypeBitSize &&
465466
Limit->getAPInt().getActiveBits() < RangeCheckTypeBitSize;
466467
}
@@ -477,7 +478,8 @@ static Optional<LoopICmp> generateLoopLatchCheck(const DataLayout &DL,
477478
if (RangeCheckType == LatchType)
478479
return LatchCheck;
479480
// For now, bail out if latch type is narrower than range type.
480-
if (DL.getTypeSizeInBits(LatchType) < DL.getTypeSizeInBits(RangeCheckType))
481+
if (DL.getTypeSizeInBits(LatchType).getFixedSize() <
482+
DL.getTypeSizeInBits(RangeCheckType).getFixedSize())
481483
return None;
482484
if (!isSafeToTruncateWideIVType(DL, SE, LatchCheck, RangeCheckType))
483485
return None;

llvm/lib/Transforms/Scalar/NaryReassociate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
375375
// Replace the I-th index with LHS.
376376
IndexExprs[I] = SE->getSCEV(LHS);
377377
if (isKnownNonNegative(LHS, *DL, 0, AC, GEP, DT) &&
378-
DL->getTypeSizeInBits(LHS->getType()) <
379-
DL->getTypeSizeInBits(GEP->getOperand(I)->getType())) {
378+
DL->getTypeSizeInBits(LHS->getType()).getFixedSize() <
379+
DL->getTypeSizeInBits(GEP->getOperand(I)->getType()).getFixedSize()) {
380380
// Zero-extend LHS if it is non-negative. InstCombine canonicalizes sext to
381381
// zext if the source operand is proved non-negative. We should do that
382382
// consistently so that CandidateExpr more likely appears before. See

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,8 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
20202020
// Put pointers at the back and make sure pointer < pointer = false.
20212021
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy())
20222022
return RHS->getType()->isIntegerTy() && !LHS->getType()->isIntegerTy();
2023-
return RHS->getType()->getPrimitiveSizeInBits() <
2024-
LHS->getType()->getPrimitiveSizeInBits();
2023+
return RHS->getType()->getPrimitiveSizeInBits().getFixedSize() <
2024+
LHS->getType()->getPrimitiveSizeInBits().getFixedSize();
20252025
});
20262026

20272027
unsigned NumElim = 0;

0 commit comments

Comments
 (0)