From bf60bb26ecbf4dace2a03886180be66b3ef5608a Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Mon, 26 Oct 2020 17:40:31 +0000 Subject: [PATCH] [SVE] Fix TypeSize warning in llvm::getGEPInductionOperand We do not need to use the implicit cast here. We can instead can rely on a comparison between two TypeSize objects instead. This algorithm will work fine with scalable vectors. Reviewed By: DavidTruby Differential Revision: https://reviews.llvm.org/D90146 --- llvm/lib/Analysis/VectorUtils.cpp | 2 +- .../gep-induction-operand-typesize-warning.ll | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Analysis/LoopAccessAnalysis/gep-induction-operand-typesize-warning.ll diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index 79be29c4533c..e86508758be6 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -136,7 +136,7 @@ Intrinsic::ID llvm::getVectorIntrinsicIDForCall(const CallInst *CI, unsigned llvm::getGEPInductionOperand(const GetElementPtrInst *Gep) { const DataLayout &DL = Gep->getModule()->getDataLayout(); unsigned LastOperand = Gep->getNumOperands() - 1; - unsigned GEPAllocSize = DL.getTypeAllocSize(Gep->getResultElementType()); + TypeSize GEPAllocSize = DL.getTypeAllocSize(Gep->getResultElementType()); // Walk backwards and try to peel off zeros. while (LastOperand > 1 && match(Gep->getOperand(LastOperand), m_Zero())) { diff --git a/llvm/test/Analysis/LoopAccessAnalysis/gep-induction-operand-typesize-warning.ll b/llvm/test/Analysis/LoopAccessAnalysis/gep-induction-operand-typesize-warning.ll new file mode 100644 index 000000000000..7e4e5bacd12b --- /dev/null +++ b/llvm/test/Analysis/LoopAccessAnalysis/gep-induction-operand-typesize-warning.ll @@ -0,0 +1,25 @@ +; RUN: opt -loop-load-elim -mtriple=aarch64--linux-gnu -mattr=+sve < %s 2>%t +; 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 in the llvm::getGEPInductionOperand function. + +; 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 @get_gep_induction_operand_typesize_warning(i64 %n, * %a) { +entry: + br label %loop.body + +loop.body: + %0 = phi i64 [ 0, %entry ], [ %1, %loop.body ] + %idx = getelementptr , * %a, i64 %0 + store zeroinitializer, * %idx + %1 = add i64 %0, 1 + %2 = icmp eq i64 %1, %n + br i1 %2, label %loop.end, label %loop.body + +loop.end: + ret void +}