[PATCH] D89798: [SVE][AArch64] Fix TypeSize warning in loop vectorization legality

Joe Ellis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 09:13:31 PDT 2020


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

Address peterwaller-arm's comments regarding control flow readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89798

Files:
  llvm/lib/Analysis/Loads.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
  llvm/test/Transforms/LoopVectorize/AArch64/sve-scalable-load-in-loop.ll


Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-scalable-load-in-loop.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-scalable-load-in-loop.ll
@@ -0,0 +1,41 @@
+; RUN: opt -S -O2 -mtriple=aarch64-linux-gnu -mattr=+sve < %s 2>%t | FileCheck %s
+; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
+
+; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
+; WARN-NOT: warning: {{.*}}TypeSize is not scalable
+
+; #include <arm_sve.h>
+;
+; void scalable_load_in_loop(long n, int *a, int *b, svuint32_t *x,
+;                            svuint32_t *y) {
+;     for (unsigned i = 0; i < n; i++) {
+;         if (i % 2 == 0) continue;
+;         a[i] = 2 * b[i];
+;         *x = *y;
+;     }
+; }
+
+; CHECK-LABEL: @scalable_load_in_loop
+define void @scalable_load_in_loop(i64 %n, <vscale x 4 x i32>* %x, <vscale x 4 x i32>* %y) {
+entry:
+  br label %for.body
+
+for.body:
+  %i = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
+  %rem = and i32 %i, 1
+  %cmp = icmp eq i32 %rem, 0
+  br i1 %cmp, label %for.inc, label %if.end
+
+if.end:
+  %0 = load <vscale x 4 x i32>, <vscale x 4 x i32>* %y
+  store <vscale x 4 x i32> %0, <vscale x 4 x i32>* %x
+  br label %for.inc
+
+for.inc:
+  %inc = add i32 %i, 1
+  %cmp2 = icmp slt i64 0, %n
+  br i1 %cmp2, label %for.body, label %for.cleanup
+
+for.cleanup:
+  ret void
+}
Index: llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -1009,9 +1009,17 @@
     ScalarEvolution &SE = *PSE.getSE();
     for (Instruction &I : *BB) {
       LoadInst *LI = dyn_cast<LoadInst>(&I);
-      if (LI && !mustSuppressSpeculation(*LI) &&
-          isDereferenceableAndAlignedInLoop(LI, TheLoop, SE, *DT))
-        SafePointers.insert(LI->getPointerOperand());
+      if (!LI)
+        continue;
+      // Don't consider vector loads; it does not make sense in the context of
+      // identifying scalar loads for vectorization.
+      if (LI->getType()->isVectorTy())
+        continue;
+      if (mustSuppressSpeculation(*LI))
+        continue;
+      if (!isDereferenceableAndAlignedInLoop(LI, TheLoop, SE, *DT))
+        continue;
+      SafePointers.insert(LI->getPointerOperand());
     }
   }
 
Index: llvm/lib/Analysis/Loads.cpp
===================================================================
--- llvm/lib/Analysis/Loads.cpp
+++ llvm/lib/Analysis/Loads.cpp
@@ -199,7 +199,7 @@
   Value *Ptr = LI->getPointerOperand();
 
   APInt EltSize(DL.getIndexTypeSizeInBits(Ptr->getType()),
-                DL.getTypeStoreSize(LI->getType()));
+                DL.getTypeStoreSize(LI->getType()).getFixedSize());
   const Align Alignment = LI->getAlign();
 
   Instruction *HeaderFirstNonPHI = L->getHeader()->getFirstNonPHI();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89798.299380.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201020/513ad630/attachment.bin>


More information about the llvm-commits mailing list