[PATCH] D43064: [LV] Fix analyzeInterleaving when -pass-remarks enabled

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 23:53:57 PST 2018


mtrofin created this revision.
Herald added subscribers: llvm-commits, fhahn.

If -pass-remarks=loop-vectorize, atomic ops will be seen by
analyzeinterleaving, even though canVectorizeMemory() == false. This
is because we are requesting extra analysis instead of bailing out.

In such a case, we end up with a Group in both Load and Store Groups,
which then means we'll try to access freed memory when traversing one
after releasing from the other.

The fix is to include mayWriteToMemory when validating two
instructions are the same kind of memory operation.


Repository:
  rL LLVM

https://reviews.llvm.org/D43064

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp


Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5926,7 +5926,12 @@
 
       // Ignore A if it's already in a group or isn't the same kind of memory
       // operation as B.
-      if (isInterleaved(A) || A->mayReadFromMemory() != B->mayReadFromMemory())
+      // Note that mayReadFromMemory() isn't mutually exclussive to mayWriteToMemory
+      // in the case of atomic loads. We shouldn't see those here, canVectorizeMemory()
+      // should have returned false - except for the case we asked for optimization
+      // remarks.
+      if (isInterleaved(A) || (A->mayReadFromMemory() != B->mayReadFromMemory())
+          || (A->mayWriteToMemory() != B->mayWriteToMemory()))
         continue;
 
       // Check rules 1 and 2. Ignore A if its stride or size is different from


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43064.133376.patch
Type: text/x-patch
Size: 949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180208/59154e9a/attachment.bin>


More information about the llvm-commits mailing list