[llvm] [LLVM][DAGCombiner] Port calculateByteProvider to TypeSize. (PR #148425)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 14 08:48:57 PDT 2025


================
@@ -9149,11 +9149,12 @@ calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth,
   if (Op.getOpcode() != ISD::LOAD && VectorIndex.has_value())
     return std::nullopt;
 
-  unsigned BitWidth = Op.getValueSizeInBits();
-  if (BitWidth % 8 != 0)
+  TypeSize BitWidth = Op.getValueSizeInBits();
+  if (!BitWidth.isKnownMultipleOf(8))
     return std::nullopt;
-  unsigned ByteWidth = BitWidth / 8;
-  assert(Index < ByteWidth && "invalid index requested");
+  TypeSize ByteWidth = BitWidth.divideCoefficientBy(8);
+  assert(TypeSize::isKnownLT(TypeSize::getFixed(Index), ByteWidth) &&
+         "invalid index requested");
----------------
paulwalker-arm wrote:

In general `TypeSize` and `ElementCount` are the types to use when writing code that's portable across fixed and scalable types. `getKnownMinValue()` exists for those places where the preferred types cannot be use, which is often due to interfacing with existing code.

That said, after more investigation I believe `calculateByteProvider` doesn't really care about the size of the type but instead always wants the size of the scalar type because that is what `Index` will be used to index into.

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


More information about the llvm-commits mailing list