[PATCH] D68082: [LV] Emitting SCEV checks with OptForSize

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 27 03:23:53 PDT 2019


SjoerdMeijer updated this revision to Diff 222117.
SjoerdMeijer edited the summary of this revision.
SjoerdMeijer added a comment.

Thanks for all the pointers and info, that helped me getting back on track.
Hopefully things are actually as simple as the change in this patch.


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

https://reviews.llvm.org/D68082

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/pr43371-optsize-scevchecks.ll


Index: llvm/test/Transforms/LoopVectorize/pr43371-optsize-scevchecks.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/pr43371-optsize-scevchecks.ll
@@ -0,0 +1,38 @@
+; RUN: opt -S -loop-vectorize  -pass-remarks-analysis='loop-vectorize' < %s 2>&1 | FileCheck %s
+
+ at cm_array = external global [2592 x i16], align 1
+
+define void @pr43371() optsize {
+;
+; CHECK: remark: <unknown>:0:0: loop not vectorized: runtime SCEV checks needed. Enable vectorization of this loop with '#pragma clang loop vectorize(enable)' when compiling with -Os/-Oz
+;
+; CHECK-LABEL: @pr43371
+;
+; CHECK-NOT: vector.scevcheck:
+; CHECK-NOT: vector.body:
+;
+entry:
+  br label %for.body
+
+for.cond.for.cond.cleanup_crit_edge:
+  br label %for.body29
+
+for.body:
+  br label %for.cond.for.cond.cleanup_crit_edge
+
+for.cond.cleanup28:
+  unreachable
+
+for.body29:
+  %i24.0170 = phi i16 [ 0, %for.cond.for.cond.cleanup_crit_edge ], [ %inc37, %for.inc36 ]
+  %add33 = add i16 undef, %i24.0170
+  %idxprom34 = zext i16 %add33 to i32
+  %arrayidx35 = getelementptr [2592 x i16], [2592 x i16] * @cm_array, i32 0, i32 %idxprom34
+  store i16 0, i16 * %arrayidx35, align 1
+  br label %for.inc36
+
+for.inc36:
+  %inc37 = add i16 %i24.0170, 1
+  %cmp26 = icmp ult i16 %inc37, 756
+  br i1 %cmp26, label %for.body29, label %for.cond.cleanup28
+}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6375,6 +6375,12 @@
     // Collect Uniform and Scalar instructions after vectorization with VF.
     CM.collectUniformsAndScalars(VF);
 
+    // collectUniformsAndScalars (and setCostBasedWideningDecision) change
+    // SCEV behaviour, which we haven't seen before, so check again if we need
+    // runtime checks.
+    if (CM.TheFunction->hasOptSize() && CM.runtimeChecksRequired())
+      return None;
+
     // Collect the instructions (and their associated costs) that will be more
     // profitable to scalarize.
     if (VF > 1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68082.222117.patch
Type: text/x-patch
Size: 2163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190927/d68d6630/attachment.bin>


More information about the llvm-commits mailing list