[PATCH] D89872: [SVE][AArch64] Fix TypeSize warning in GEP cost analysis

Joe Ellis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 21 07:48:34 PDT 2020


joechrisellis updated this revision to Diff 299689.
joechrisellis added a comment.

Bail out early if we have scalable vectors.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89872/new/

https://reviews.llvm.org/D89872

Files:
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/test/Analysis/CostModel/AArch64/gep-cost-scalable-vector-typesize-warning.ll


Index: llvm/test/Analysis/CostModel/AArch64/gep-cost-scalable-vector-typesize-warning.ll
===================================================================
--- /dev/null
+++ 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(<vscale x 4 x i32>* %x);
+
+; CHECK-LABEL: @gep_scalable_vector
+; CHECK-NOT: vector.body
+define void @gep_scalable_vector(<vscale x 4 x i32>* %b) {
+entry:
+  br label %loop.body
+loop.body:
+  %0 = phi i64 [0, %entry], [%1, %loop.body]
+  %idx = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* %b, i64 %0
+  call void @do_something(<vscale x 4 x i32>* %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
+}
Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -797,6 +797,14 @@
 
     for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
       TargetType = GTI.getIndexedType();
+
+      // If this operand is a scalable type, bail out early.
+      // TODO: can we handle scalable vectors in a 'nicer' way here?
+      if (const VectorType *VTy = dyn_cast<VectorType>(TargetType)) {
+        if (VTy->getElementCount().isScalable())
+          return TTI::TCC_Basic;
+      }
+
       // We assume that the cost of Scalar GEP with constant index and the
       // cost of Vector GEP with splat constant index are the same.
       const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
@@ -809,7 +817,8 @@
         uint64_t Field = ConstIdx->getZExtValue();
         BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
       } else {
-        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
+        int64_t ElementSize =
+            DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize();
         if (ConstIdx) {
           BaseOffset +=
               ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89872.299689.patch
Type: text/x-patch
Size: 2725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/461956a9/attachment-0001.bin>


More information about the llvm-commits mailing list