[llvm] [LoopFusion] Fix false-positive dependency blocking fusion of idempot… (PR #206401)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 20:57:39 PDT 2026


AntonyCJ30 wrote:

Thanks for the feedback. Let me address both points:

(1) The fix checks if the store value operands are the same SSA value (`Val0 == Val1`). This is a simple and strong guarantee — if they come from the same definition, they are identical at runtime. SCEV equality isn't used here; it's a direct SSA value comparison.

(2) I understand your concern about covering cases without real-world evidence. This came from observing that simple patterns like:

void foo(int *a, int *b, int n, int v) {
    for (int i = 0; i < n; i++) a[i] = v;
    for (int i = 0; i < n; i++) b[i] = v;
}

or

void foo(int *a, int *b, int n, int x, int y) {
    int v1 = x + y;
    int v2 = x + y;
    for (int i = 0; i < n; i++) a[i] = v1;
    for (int i = 0; i < n; i++) b[i] = v2;
}

are not fused because DA returns MayAlias, even though fusion is clearly safe. These seem like realistic code patterns that could appear in practice.

If you think this optimization is worth having, I can proceed with cleaning up and adding tests. Otherwise, I'm happy to close this. Please let me know.

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


More information about the llvm-commits mailing list