[PATCH] D146958: [SCEV] Do not plant SCEV checks unnecessarily

Paul Osmialowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 09:14:51 PDT 2023


pawosm01 updated this revision to Diff 510836.
pawosm01 added a comment.

the context also restored


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146958

Files:
  llvm/lib/Analysis/LoopAccessAnalysis.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll


Index: llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll
@@ -0,0 +1,38 @@
+; RUN: opt -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -S < %s | FileCheck %s
+
+define void @foo(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {
+; CHECK-LABEL: @foo(
+; CHECK-NOT: vector.scevcheck
+; CHECK: vector.body
+entry:
+  %0 = getelementptr double, ptr %pin, i64 %val0
+  br label %loop1.header
+
+loop1.header:                                     ; preds = %loop1.latch, %entry
+  %i = phi i64 [ %i.next, %loop1.latch ], [ 0, %entry ]
+  %mul0 = mul nsw i64 %i, %val2
+  %arrayidx0 = getelementptr inbounds double, ptr %0, i64 %mul0
+  %mul1 = mul nsw i64 %i, %val1
+  br label %loop2.header
+
+loop2.header:                                     ; preds = %loop1.header, %loop2.header
+  %j = phi i64 [ 0, %loop1.header ], [ %j.next, %loop2.header ]
+  %1 = load double, ptr %arrayidx0, align 8
+  %arrayidx1 = getelementptr inbounds double, ptr %0, i64 %j
+  %2 = load double, ptr %arrayidx1, align 8
+  %sum = fadd contract double %1, %2
+  %3 = getelementptr double, ptr %pout, i64 %mul1
+  %arrayidx2 = getelementptr inbounds double, ptr %3, i64 %j
+  store double %sum, ptr %arrayidx2, align 8
+  %j.next = add nuw nsw i64 %j, 1
+  %cmp = icmp slt i64 %j.next, %val1
+  br i1 %cmp, label %loop2.header, label %loop1.latch
+
+loop1.latch:                                      ; preds = %loop2.header
+  %i.next = add nuw nsw i64 %i, 1
+  %exitcond = icmp eq i64 %i.next, %val1
+  br i1 %exitcond, label %exit, label %loop1.header
+
+exit:                                             ; preds = %loop1.latch
+  ret void
+}
Index: llvm/lib/Analysis/VectorUtils.cpp
===================================================================
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -1157,6 +1157,12 @@
       Value *Ptr = getLoadStorePointerOperand(&I);
       if (!Ptr)
         continue;
+
+      // If the pointer is invariant then there is no stride and it makes no
+      // sense to add it here.
+      if (TheLoop->isLoopInvariant(Ptr))
+        continue;
+
       Type *ElementTy = getLoadStoreType(&I);
 
       // Currently, codegen doesn't support cases where the type size doesn't
Index: llvm/lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2561,6 +2561,11 @@
   if (!Ptr)
     return;
 
+  // If the pointer is invariant then there is no stride and it makes no
+  // sense to add it here.
+  if (TheLoop->isLoopInvariant(Ptr))
+    return;
+
   Value *Stride = getStrideFromPointer(Ptr, PSE->getSE(), TheLoop);
   if (!Stride)
     return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146958.510836.patch
Type: text/x-patch
Size: 2907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230404/0f893f6c/attachment.bin>


More information about the llvm-commits mailing list