[all-commits] [llvm/llvm-project] da4894: [LoopFusion] reject unsafe scalar flow dependences...

Arda Serdar Pektezol via All-commits all-commits at lists.llvm.org
Wed May 27 20:01:44 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: da4894c874edb5fc9b9b82a8a99ed471a49153bf
      https://github.com/llvm/llvm-project/commit/da4894c874edb5fc9b9b82a8a99ed471a49153bf
  Author: Arda Serdar Pektezol <arda at pektezol.dev>
  Date:   2026-05-28 (Thu, 28 May 2026)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LoopFuse.cpp
    M llvm/test/Transforms/LoopFusion/loop_invariant.ll
    A llvm/test/Transforms/LoopFusion/pr191238.ll

  Log Message:
  -----------
  [LoopFusion] reject unsafe scalar flow dependences (#195895)

`loop-fusion` treats any loop-invariant scalar non-anti dependence as
safe to fuse. In the linked issue, it incorrectly allows scalar flow
dependences where the first loop writes a loop-invariant location and
the second loop later reads that same location. Fusion interleaves the
producer and consumer and this changes the value observed by the second
loop.

Example C source would look like:
```C
for (int i = 0; i < N; i++) {
    ptr[0] = i;
}
for (int j = 0; j < N; j++) {
    out[j] = ptr[0];
}
=>
for (int i = 0; i < N; i++) {
    ptr[0] = i;
    out[i] = ptr[0];
}
```

This patch makes the DA scalar-dependence shortcut **_more
conservative_** by rejecting scalar non-anti and allowing input/output
dependences. This preserves the existing safe read and write cases while
preventing the miscompile above.

The patch also updates the `loop-fusion` debug message to reflect the
narrower accepted case, updates the existing regression to check the new
debug message, and adds a new regression from the linked issue.

Fixes #191238



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list