diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -228,9 +228,9 @@ } // Add the size of the pointed element to ScEnd. auto &DL = Lp->getHeader()->getModule()->getDataLayout(); - unsigned EltSize = - DL.getTypeStoreSizeInBits(Ptr->getType()->getPointerElementType()) / 8; - const SCEV *EltSizeSCEV = SE->getConstant(ScEnd->getType(), EltSize); + Type *IntIdxTy = DL.getIndexType(Ptr->getType()); + const SCEV *EltSizeSCEV = + SE->getSizeOfExpr(IntIdxTy, Ptr->getType()->getPointerElementType()); ScEnd = SE->getAddExpr(ScEnd, EltSizeSCEV); } diff --git a/llvm/test/Analysis/LoopAccessAnalysis/runtime-pointer-checking-insert-typesize.ll b/llvm/test/Analysis/LoopAccessAnalysis/runtime-pointer-checking-insert-typesize.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/LoopAccessAnalysis/runtime-pointer-checking-insert-typesize.ll @@ -0,0 +1,27 @@ +; RUN: opt -loop-accesses -analyze < %s >/dev/null 2>%t +; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t + +; This regression test is defending against a TypeSize warning 'assumption that +; TypeSize is not scalable'. This warning cropped up in +; RuntimePointerChecking::insert when performing loop load elimination because +; this function was previously unaware of scalable types. + +; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it. +; WARN-NOT: warning: {{.*}}TypeSize is not scalable + +define void @runtime_pointer_checking_insert_typesize(* %a, + * %b) { +entry: + br label %loop.body +loop.body: + %0 = phi i64 [ 0, %entry ], [%1, %loop.body] + %idx_a = getelementptr , * %a, i64 %0 + %idx_b = getelementptr , * %b, i64 %0 + %tmp = load , * %idx_a + store %tmp, * %idx_b + %1 = add i64 %0, 2 + %2 = icmp eq i64 %1, 1024 + br i1 %2, label %loop.end, label %loop.body +loop.end: + ret void +}