[llvm] [LV] Restrict widest induction type to be IntegerType (NFC) (PR #128173)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 21 10:19:15 PST 2025


================
@@ -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());
----------------
artagnon wrote:

So, the reason for this change is that there are two equivalent `getIntPtrType` APIs:

```cpp
IntegerType *DataLayout::getIntPtrType(LLVMContext &C,
                                       unsigned AddressSpace) const {
  return IntegerType::get(C, getPointerSizeInBits(AddressSpace));
}

Type *DataLayout::getIntPtrType(Type *Ty) const {
  assert(Ty->isPtrOrPtrVectorTy() &&
         "Expected a pointer or pointer vector type.");
  unsigned NumBits = getPointerTypeSizeInBits(Ty);
  IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
  if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
    return VectorType::get(IntTy, VecTy);
  return IntTy;
}
```

The `Type *` variant does a little bit of extra work, but for our case, the `IntegerType *` variant should do the same thing with less work. Note that `getPointerTypeSizeInBits` on `Type` ultimately extracts the AddressSpace.

https://github.com/llvm/llvm-project/pull/128173


More information about the llvm-commits mailing list