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

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 09:16:45 PDT 2019


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

- modified SCEV so that it doesn't add Predicates when OptForSize is enabled. This has indeed the consequence that vectorisation will happen, it will scalarise the stores.
- moved the test case to an exisiting optsize file.


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

https://reviews.llvm.org/D68082

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Transforms/LoopVectorize/X86/optsize.ll


Index: llvm/test/Transforms/LoopVectorize/X86/optsize.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/X86/optsize.ll
+++ llvm/test/Transforms/LoopVectorize/X86/optsize.ll
@@ -4,6 +4,7 @@
 ; attributes. This is a target-dependent version of the test.
 ; RUN: opt < %s -loop-vectorize -force-vector-width=64 -S -mtriple=x86_64-unknown-linux -mcpu=skx | FileCheck %s
 ; RUN: opt < %s -loop-vectorize -S -mtriple=x86_64-unknown-linux -mcpu=skx | FileCheck %s --check-prefix AUTOVF
+; RUN: opt < %s -loop-vectorize -S | FileCheck %s --check-prefix=NO-SCEV-PREDS
 
 target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S128"
 
@@ -196,3 +197,48 @@
 while.cond.loopexit:
   ret i32 0
 }
+
+; PR43371: don't run in an assert while emitting SCEV runtime checks
+; with OptForSize.
+;
+ at cm_array = external global [2592 x i16], align 1
+
+define void @pr43371() optsize {
+;
+; NO-SCEV-PREDS-LABEL: @pr43371
+;
+; SCEV should not generate predicates while optimising for size, because
+; code will be generated for predicates, such as the SCEV overflow runtime
+; checks. As a result of not generatig SCEV predicates, getPtrStride returns
+; that stores/loads are not consecutive, so that they will be scalarized:
+;
+; NO-SCEV-PREDS: vector.body:
+; NO-SCEV-PREDS: store i16 0, i16* %{{.*}}, align 1
+; NO-SCEV-PREDS: store i16 0, i16* %{{.*}}, align 1
+; NO-SCEV-PREDS: br i1 {{.*}}, label %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/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12414,6 +12414,11 @@
   if (!New)
     return nullptr;
 
+  // Don't add predicates when we optimize for code-size.
+  const auto *I = dyn_cast<Instruction>(V);
+  if (I->getParent()->getParent()->hasOptSize())
+    return nullptr;
+
   for (auto *P : NewPreds)
     Preds.add(P);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68082.222449.patch
Type: text/x-patch
Size: 2638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/2d670c65/attachment.bin>


More information about the llvm-commits mailing list