Index: llvm/lib/IR/Operator.cpp =================================================================== --- llvm/lib/IR/Operator.cpp +++ llvm/lib/IR/Operator.cpp @@ -39,6 +39,11 @@ for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this); GTI != GTE; ++GTI) { + // Scalable vectors have are multiplied by a runtime constant. + if (auto *VecTy = dyn_cast(GTI.getIndexedType())) + if (VecTy->isScalable()) + return false; + ConstantInt *OpC = dyn_cast(GTI.getOperand()); if (!OpC) return false; Index: llvm/test/Transforms/InstCombine/gep-vector.ll =================================================================== --- llvm/test/Transforms/InstCombine/gep-vector.ll +++ llvm/test/Transforms/InstCombine/gep-vector.ll @@ -134,3 +134,15 @@ %gep = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* %asc, i64 %y, i64 %z ret i32 addrspace(3)* %gep } + +; Negative test - avoid doing bitcast on i8*, because '16' should be scaled by 'vscale'. + +define @test_accumulate_constant_offset_vscale( %pg, i8* %base) { +; CHECK-LABEL: @test_accumulate_constant_offset_vscale +; CHECK-NEXT: %bc = bitcast i8* %base to * +; CHECK-NEXT: %gep = getelementptr , * %bc, i64 1 +; CHECK-NEXT: ret %gep + %bc = bitcast i8* %base to * + %gep = getelementptr , * %bc, i64 1 + ret %gep +}