Index: llvm/lib/IR/ConstantFold.cpp =================================================================== --- llvm/lib/IR/ConstantFold.cpp +++ llvm/lib/IR/ConstantFold.cpp @@ -2298,18 +2298,17 @@ assert(Ty && "Invalid indices for GEP!"); Type *OrigGEPTy = PointerType::get(Ty, PtrTy->getAddressSpace()); Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace()); - if (VectorType *VT = dyn_cast(C->getType())) { - // FIXME: handle scalable vectors (use getElementCount()) - GEPTy = FixedVectorType::get( - OrigGEPTy, cast(VT)->getNumElements()); - } + if (VectorType *VT = dyn_cast(C->getType())) + GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount()); + // The GEP returns a vector of pointers when one of more of // its arguments is a vector. for (unsigned i = 0, e = Idxs.size(); i != e; ++i) { if (auto *VT = dyn_cast(Idxs[i]->getType())) { - // FIXME: handle scalable vectors - GEPTy = FixedVectorType::get( - OrigGEPTy, cast(VT)->getNumElements()); + assert((!isa(GEPTy) || isa(GEPTy) == + isa(VT)) && + "Mismatched GEPTy vector types"); + GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount()); break; } } Index: llvm/test/Transforms/InstSimplify/gep.ll =================================================================== --- llvm/test/Transforms/InstSimplify/gep.ll +++ llvm/test/Transforms/InstSimplify/gep.ll @@ -168,4 +168,12 @@ ret %gep } +define @ptr_idx_mix_scalar_scalable_vector() { +; CHECK-LABEL: @ptr_idx_mix_scalar_scalable_vector( +; CHECK-NEXT: ret zeroinitializer +; + %v = getelementptr [2 x i64], [2 x i64]* null, i64 0, zeroinitializer + ret %v +} + ; Check ConstantExpr::getGetElementPtr() using ElementCount for size queries - end.