diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4094,7 +4094,7 @@ if (!IsScalableVec && Ty->isSized()) { Value *P; uint64_t C; - uint64_t TyAllocSize = Q.DL.getTypeAllocSize(Ty); + uint64_t TyAllocSize = Q.DL.getTypeAllocSize(Ty).getFixedSize(); // getelementptr P, N -> P if P points to a type of zero size. if (TyAllocSize == 0 && Ops[0]->getType() == GEPTy) return Ops[0]; @@ -4139,12 +4139,15 @@ } } - if (!IsScalableVec && Q.DL.getTypeAllocSize(LastType) == 1 && + if (!IsScalableVec && Q.DL.getTypeAllocSize(LastType).getFixedSize() == 1 && all_of(Ops.slice(1).drop_back(1), [](Value *Idx) { return match(Idx, m_Zero()); })) { unsigned IdxWidth = Q.DL.getIndexSizeInBits(Ops[0]->getType()->getPointerAddressSpace()); - if (Q.DL.getTypeSizeInBits(Ops.back()->getType()) == IdxWidth) { + // Skip if offset type size is not a compile-time constant. + TypeSize OffsetTypeSize = Q.DL.getTypeSizeInBits(Ops.back()->getType()); + if (!OffsetTypeSize.isScalable() && + OffsetTypeSize.getFixedSize() == IdxWidth) { APInt BasePtrOffset(IdxWidth, 0); Value *StrippedBasePtr = Ops[0]->stripAndAccumulateInBoundsConstantOffsets(Q.DL,