Skip to content

Commit 678dcf1

Browse files
authored
[IR] Fix a few implicit conversions from TypeSize to uint64_t. NFC (#159894)
1 parent 2ed7b9f commit 678dcf1

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

llvm/include/llvm/Analysis/MemoryLocation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class LocationSize {
146146
if (isScalable() || Other.isScalable())
147147
return afterPointer();
148148

149-
return upperBound(std::max(getValue(), Other.getValue()));
149+
return upperBound(
150+
std::max(getValue().getFixedValue(), Other.getValue().getFixedValue()));
150151
}
151152

152153
bool hasValue() const {

llvm/include/llvm/CodeGenTypes/MachineValueType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ namespace llvm {
202202
/// bitwidth.
203203
MVT changeVectorElementTypeToInteger() const {
204204
MVT EltTy = getVectorElementType();
205-
MVT IntTy = MVT::getIntegerVT(EltTy.getSizeInBits());
205+
MVT IntTy = MVT::getIntegerVT(EltTy.getFixedSizeInBits());
206206
MVT VecTy = MVT::getVectorVT(IntTy, getVectorElementCount());
207207
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
208208
"Simple vector VT not representable by simple integer vector VT!");
@@ -224,7 +224,7 @@ namespace llvm {
224224
MVT changeTypeToInteger() {
225225
if (isVector())
226226
return changeVectorElementTypeToInteger();
227-
return MVT::getIntegerVT(getSizeInBits());
227+
return MVT::getIntegerVT(getFixedSizeInBits());
228228
}
229229

230230
/// Return a VT for a vector type with the same element type but

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ class VectorType : public Type {
479479
/// the input type, and the element type is an integer type of the same width
480480
/// as the input element type.
481481
static VectorType *getInteger(VectorType *VTy) {
482-
unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
482+
unsigned EltBits =
483+
VTy->getElementType()->getPrimitiveSizeInBits().getFixedValue();
483484
assert(EltBits && "Element size must be of a non-zero size");
484485
Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
485486
return VectorType::get(EltTy, VTy->getElementCount());
@@ -510,7 +511,8 @@ class VectorType : public Type {
510511
llvm_unreachable("Cannot create narrower fp vector element type");
511512
}
512513
} else {
513-
unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
514+
unsigned EltBits =
515+
VTy->getElementType()->getPrimitiveSizeInBits().getFixedValue();
514516
assert((EltBits & 1) == 0 &&
515517
"Cannot truncate vector element with odd bit-width");
516518
EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);

llvm/lib/IR/Constants.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ uint64_t ConstantDataSequential::getNumElements() const {
28642864
}
28652865

28662866
uint64_t ConstantDataSequential::getElementByteSize() const {
2867-
return getElementType()->getPrimitiveSizeInBits() / 8;
2867+
return getElementType()->getPrimitiveSizeInBits().getFixedValue() / 8;
28682868
}
28692869

28702870
/// Return the start of the specified element.

llvm/lib/IR/Instructions.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,8 +3234,12 @@ CastInst::getCastOpcode(
32343234
}
32353235

32363236
// Get the bit sizes, we'll need these
3237-
unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3238-
unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3237+
// FIXME: This doesn't work for scalable vector types with different element
3238+
// counts that don't call getElementType above.
3239+
unsigned SrcBits =
3240+
SrcTy->getPrimitiveSizeInBits().getFixedValue(); // 0 for ptr
3241+
unsigned DestBits =
3242+
DestTy->getPrimitiveSizeInBits().getFixedValue(); // 0 for ptr
32393243

32403244
// Run through the possibilities ...
32413245
if (DestTy->isIntegerTy()) { // Casting to integral

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4411,7 +4411,7 @@ void Verifier::visitNoaliasAddrspaceMetadata(Instruction &I, MDNode *Range,
44114411
}
44124412

44134413
void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) {
4414-
unsigned Size = DL.getTypeSizeInBits(Ty);
4414+
unsigned Size = DL.getTypeSizeInBits(Ty).getFixedValue();
44154415
Check(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I);
44164416
Check(!(Size & (Size - 1)),
44174417
"atomic memory access' operand must have a power-of-two size", Ty, I);

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,8 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
24352435
// Handle integer-to-integer widening and narrowing.
24362436
// FIXME: Use DW_OP_convert when it's available everywhere.
24372437
if (FromTy->isIntegerTy() && ToTy->isIntegerTy()) {
2438-
uint64_t FromBits = FromTy->getPrimitiveSizeInBits();
2439-
uint64_t ToBits = ToTy->getPrimitiveSizeInBits();
2438+
uint64_t FromBits = FromTy->getIntegerBitWidth();
2439+
uint64_t ToBits = ToTy->getIntegerBitWidth();
24402440
assert(FromBits != ToBits && "Unexpected no-op conversion");
24412441

24422442
// When the width of the result grows, assume that a debugger will only

llvm/utils/TableGen/Common/DAGISelMatcher.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,9 @@ class EmitIntegerMatcher : public Matcher {
838838

839839
public:
840840
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt, unsigned resultNo)
841-
: Matcher(EmitInteger), Val(SignExtend64(val, MVT(vt).getSizeInBits())),
842-
VT(vt), ResultNo(resultNo) {}
841+
: Matcher(EmitInteger),
842+
Val(SignExtend64(val, MVT(vt).getFixedSizeInBits())), VT(vt),
843+
ResultNo(resultNo) {}
843844

844845
int64_t getValue() const { return Val; }
845846
MVT::SimpleValueType getVT() const { return VT; }

0 commit comments

Comments
 (0)