diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -809,7 +809,13 @@ uint64_t Field = ConstIdx->getZExtValue(); BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field); } else { - int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType()); + // If this operand is a scalable type, bail out early. + // TODO: handle scalable vectors + if (isa(TargetType)) + return TTI::TCC_Basic; + + int64_t ElementSize = + DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize(); if (ConstIdx) { BaseOffset += ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize; diff --git a/llvm/test/Analysis/CostModel/AArch64/gep-cost-scalable-vector-typesize-warning.ll b/llvm/test/Analysis/CostModel/AArch64/gep-cost-scalable-vector-typesize-warning.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/AArch64/gep-cost-scalable-vector-typesize-warning.ll @@ -0,0 +1,28 @@ +; RUN: opt -S -O2 -mtriple=aarch64-linux-gnu -mattr=+sve < %s 2>%t | FileCheck %s +; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t + +; This regression test is verifying that a GEP instruction performed on a +; scalable vector does not produce a 'assumption that TypeSize is not scalable' +; warning when performing cost analysis. +; Note that a loop is necessary here to ensure that cost analysis takes place. + +; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it. +; WARN-NOT: warning: {{.*}}TypeSize is not scalable + +declare void @do_something(* %x); + +; CHECK-LABEL: @gep_scalable_vector +; CHECK-NOT: vector.body +define void @gep_scalable_vector(* %b) { +entry: + br label %loop.body +loop.body: + %0 = phi i64 [0, %entry], [%1, %loop.body] + %idx = getelementptr , * %b, i64 %0 + call void @do_something(* %idx) + %1 = add i64 %0, 1 + %2 = icmp eq i64 %1, 1000 + br i1 %2, label %loop.end, label %loop.body +loop.end: + ret void +}