[PATCH] D128523: [LV][NFC] Fix the condition for printing debug messages

Mel Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 28 07:05:45 PDT 2022


Mel-Chen updated this revision to Diff 440607.
Mel-Chen added a comment.
Herald added subscribers: pcwang-thead, luke957, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb.

Add a test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128523

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/RISCV/force-vect-msg.ll


Index: llvm/test/Transforms/LoopVectorize/RISCV/force-vect-msg.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/RISCV/force-vect-msg.ll
@@ -0,0 +1,56 @@
+; REQUIRES: asserts
+; RUN: opt < %s -loop-vectorize -mtriple riscv64 -riscv-v-vector-bits-min=128 -mattr="+v" -debug-only=loop-vectorize -S 2>&1 | FileCheck %s
+
+; CHECK: LV: Loop hints: force=enabled
+; CHECK: LV: Scalar loop costs: 7.
+; ChosenFactor.Cost is 8, but the real cost will be divided by the width, which is 4.
+; CHECK: LV: Vector loop of width 2 costs: 4.
+; CHECK-NOT: LV: Vectorization seems to be not beneficial, but was forced by a user.
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
+target triple = "riscv64-unknown-unknown"
+
+;
+; The test case is from:
+;
+; #include <stddef.h>
+; long foo(long *a, size_t N, long init) {
+;   long rd = init;
+;   for (size_t i = 0; i < N; ++i)
+;     rd += a[i];
+;
+;   return rd;
+; }
+;
+
+;
+; Regardless of force vectorization or not, this loop will eventually be vectorized because of the cost model.
+; Therefore, the following message does not need to be printed even if vectorization is explicitly forced in the metadata.
+; LV: Vectorization seems to be not beneficial, but was forced by a user.
+;
+
+define i64 @foo(ptr nocapture noundef readonly %a, i64 noundef %N, i64 noundef %init) {
+entry:
+  %cmp4.not = icmp eq i64 %N, 0
+  br i1 %cmp4.not, label %for.cond.cleanup, label %for.body.preheader
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body, %entry
+  %rd.0.lcssa = phi i64 [ %init, %entry ], [ %add, %for.body ]
+  ret i64 %rd.0.lcssa
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+  %i.06 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ]
+  %rd.05 = phi i64 [ %add, %for.body ], [ %init, %for.body.preheader ]
+  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %i.06
+  %0 = load i64, ptr %arrayidx, align 8
+  %add = add nsw i64 %0, %rd.05
+  %inc = add nuw i64 %i.06, 1
+  %exitcond.not = icmp eq i64 %inc, %N
+  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !0
+}
+
+!0 = !{!0, !1}
+!1 = !{!"llvm.loop.vectorize.enable", i1 true}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5418,7 +5418,7 @@
   }
 
   LLVM_DEBUG(if (ForceVectorization && !ChosenFactor.Width.isScalar() &&
-                 ChosenFactor.Cost >= ScalarCost.Cost) dbgs()
+                 !isMoreProfitable(ChosenFactor, ScalarCost)) dbgs()
              << "LV: Vectorization seems to be not beneficial, "
              << "but was forced by a user.\n");
   LLVM_DEBUG(dbgs() << "LV: Selecting VF: " << ChosenFactor.Width << ".\n");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128523.440607.patch
Type: text/x-patch
Size: 3025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220628/cb84cd71/attachment.bin>


More information about the llvm-commits mailing list