[PATCH] D55798: [LAA] Avoid generating RT checks for known deps preventing vectorization.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 17 17:20:11 PST 2018


fhahn created this revision.
fhahn added reviewers: Ayal, anemet, hsaito.
fhahn added a parent revision: D54892: [LAA] Introduce enum for vectorization safety status (NFC)..

If we found unsafe dependences other than 'unknown', we already know at
compile time that they are unsafe and the runtime checks should always
fail. So we can avoid generating them in those cases.

This should have no negative impact on performance as the runtime checks
that would be created previously should always fail. As a sanity check,
I measured the test-suite, spec2k and spec2k6 and there were no regressions.


Repository:
  rL LLVM

https://reviews.llvm.org/D55798

Files:
  include/llvm/Analysis/LoopAccessAnalysis.h
  lib/Analysis/LoopAccessAnalysis.cpp
  test/Transforms/LoopVectorize/runtime-check.ll


Index: test/Transforms/LoopVectorize/runtime-check.ll
===================================================================
--- test/Transforms/LoopVectorize/runtime-check.ll
+++ test/Transforms/LoopVectorize/runtime-check.ll
@@ -117,7 +117,9 @@
   ret void
 }
 
-; Check we do generate unnecessary runtime checks. They will always fail.
+; Check we do not generate runtime checks if we found a known dependence preventing
+; vectorization. In this case, it is a read of c[i-1] followed by a write of c[i].
+; The runtime checks would always fail.
 
 ; void test_runtime_check2(float *a, float b, unsigned offset, unsigned offset2, unsigned n, float *c) {
 ;   for (unsigned i = 1; i < n; i++) {
@@ -127,7 +129,7 @@
 ; }
 ;
 ; CHECK-LABEL: test_runtime_check2
-; CHECK:      <4 x float>
+; CHECK-NOT:      <4 x float>
 define void @test_runtime_check2(float* %a, float %b, i64 %offset, i64 %offset2, i64 %n, float* %c) {
 entry:
   br label %for.body
Index: lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- lib/Analysis/LoopAccessAnalysis.cpp
+++ lib/Analysis/LoopAccessAnalysis.cpp
@@ -1230,6 +1230,7 @@
     return VectorizationSafetyStatus::Safe;
 
   case Unknown:
+    return VectorizationSafetyStatus::SafeWithRtChecks;
   case ForwardButPreventsForwarding:
   case Backward:
   case BackwardVectorizableButPreventsForwarding:
Index: include/llvm/Analysis/LoopAccessAnalysis.h
===================================================================
--- include/llvm/Analysis/LoopAccessAnalysis.h
+++ include/llvm/Analysis/LoopAccessAnalysis.h
@@ -102,6 +102,8 @@
     // Can vectorize safely without RT checks. All dependences are known to be
     // safe.
     Safe,
+    // Can vectorize with RT checks to overcome unknown dependencies.
+    SafeWithRtChecks,
     // Cannot vectorize due to known unsafe dependencies.
     Unsafe,
   };
@@ -218,7 +220,7 @@
   /// vectorize the loop with a dynamic array access check.
   bool shouldRetryWithRuntimeCheck() const {
     return ShouldRetryWithRuntimeCheck &&
-           Status == VectorizationSafetyStatus::Unsafe;
+           Status == VectorizationSafetyStatus::SafeWithRtChecks;
   }
 
   /// Returns the memory dependences.  If null is returned we exceeded
@@ -284,7 +286,8 @@
   bool ShouldRetryWithRuntimeCheck;
 
   /// Result of the dependence checks, indicating whether the checked
-  /// dependences are safe for vectorization or not.
+  /// dependences are safe for vectorization, require RT checks or are known to
+  /// be unsafe.
   VectorizationSafetyStatus Status;
 
   //// True if Dependences reflects the dependences in the
@@ -320,7 +323,7 @@
   bool couldPreventStoreLoadForward(uint64_t Distance, uint64_t TypeByteSize);
 
   /// Updates the current safety status with \p S. We can go from Safe to
-  /// to Unsafe.
+  /// either SafeWithRtChecks or Unsafe and from SafeWithRtChecks to Unsafe.
   void mergeInStatus(VectorizationSafetyStatus S);
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55798.178568.patch
Type: text/x-patch
Size: 2985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181218/b9630efd/attachment.bin>


More information about the llvm-commits mailing list