[llvm] [LAA] Fix WAW dependency analysis with negative distances (PR #155266)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 05:42:46 PDT 2025


================
@@ -0,0 +1,109 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes='print<access-info>' -disable-output %s 2>&1 | FileCheck %s
+
+; Test that LAA correctly identifies Write-After-Write dependencies with negative
+; distances as unsafe. Previously, LAA would incorrectly classify negative distance
+; WAW dependencies as safe Forward dependencies, allowing inappropriate vectorization.
+;
+; This corresponds to the loop:
+;   for(int i = 0; i < n; ++i) {
+;       A[(i+1)*4] = 10;   // First store: A[4, 8, 12, 16, ...]
+;       A[i] = 100;        // Second store: A[0, 1, 2, 3, 4, ...]
+;   }
----------------
fhahn wrote:

I think I am missing something from the example.

Say we vectorize with VF = 2, then the

vector store for A[(i+1)*4] would store to [4, 8], [12,16], [20, 24]
second vector store for A[i] would store to [0,1], [2,3], [4,5]
This should ensure that the second store overwrites values of the first store in later iterations as in the scalar loop? Alive2 seems to agree that this is fine for a variant with 8 iterations: https://alive2.llvm.org/ce/z/pm6iob

https://github.com/llvm/llvm-project/pull/155266


More information about the llvm-commits mailing list