-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LAA] Add tests with non-power-of-2 store-load forward distance #136710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexey-bataev
merged 2 commits into
main
from
users/alexey-bataev/spr/lvlaanfcadd-a-test-with-non-power-of-2-store-load-forward-distance-nfc
Apr 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
260 changes: 260 additions & 0 deletions
260
llvm/test/Analysis/LoopAccessAnalysis/safe-with-dep-distance-non-power-of-2.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,260 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -passes='print<access-info>' -disable-output -mtriple=riscv64 -mattr=+v < %s 2>&1 | FileCheck %s | ||
| ; RUN: opt -passes='print<access-info>' -disable-output -mtriple=x86_64 < %s 2>&1 | FileCheck %s | ||
|
|
||
| ; REQUIRES: riscv-registered-target, x86-registered-target | ||
|
|
||
| ; Dependence distance between read and write is greater than the trip | ||
| ; count of the loop. Thus, values written are never read for any | ||
| ; valid vectorization of the loop. | ||
| define void @test(ptr %p) { | ||
| ; CHECK-LABEL: 'test' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Memory dependences are safe | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 8 | ||
| %offset = add i64 %iv, 200 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 8 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 199 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| ; Dependence distance is less than trip count, thus we must prove that | ||
| ; chosen VF guaranteed to be less than dependence distance. | ||
| define void @test_may_clobber1(ptr %p) { | ||
| ; CHECK-LABEL: 'test_may_clobber1' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Memory dependences are safe with a maximum safe vector width of 6400 bits, with a maximum safe store-load forward width of 256 bits | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: BackwardVectorizable: | ||
| ; CHECK-NEXT: %v = load i64, ptr %a1, align 32 -> | ||
| ; CHECK-NEXT: store i64 %v, ptr %a2, align 32 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 32 | ||
| %offset = add i64 %iv, 100 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 32 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 199 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_may_clobber2(ptr %p) { | ||
| ; CHECK-LABEL: 'test_may_clobber2' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop | ||
| ; CHECK-NEXT: Backward loop carried data dependence that prevents store-to-load forwarding. | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: BackwardVectorizableButPreventsForwarding: | ||
| ; CHECK-NEXT: %v = load i64, ptr %a1, align 32 -> | ||
| ; CHECK-NEXT: store i64 %v, ptr %a2, align 32 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 32 | ||
| %offset = add i64 %iv, 9 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 32 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 199 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_may_clobber3(ptr %p) { | ||
| ; CHECK-LABEL: 'test_may_clobber3' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Memory dependences are safe with a maximum safe vector width of 640 bits, with a maximum safe store-load forward width of 128 bits | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: BackwardVectorizable: | ||
| ; CHECK-NEXT: %v = load i64, ptr %a1, align 32 -> | ||
| ; CHECK-NEXT: store i64 %v, ptr %a2, align 32 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 32 | ||
| %offset = add i64 %iv, 10 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 32 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 199 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| ; Trvially no overlap due to maximum possible value of VLEN and LMUL | ||
| define void @trivial_due_max_vscale(ptr %p) { | ||
| ; CHECK-LABEL: 'trivial_due_max_vscale' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Memory dependences are safe | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 32 | ||
| %offset = add i64 %iv, 8192 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 32 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 199 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| ; Dependence distance could be violated via LMUL>=2 or interleaving | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| define void @no_high_lmul_or_interleave(ptr %p) { | ||
| ; CHECK-LABEL: 'no_high_lmul_or_interleave' | ||
| ; CHECK-NEXT: loop: | ||
| ; CHECK-NEXT: Memory dependences are safe with a maximum safe vector width of 65536 bits | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: BackwardVectorizable: | ||
| ; CHECK-NEXT: %v = load i64, ptr %a1, align 32 -> | ||
| ; CHECK-NEXT: store i64 %v, ptr %a2, align 32 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %iv = phi i64 [0, %entry], [%iv.next, %loop] | ||
| %a1 = getelementptr i64, ptr %p, i64 %iv | ||
| %v = load i64, ptr %a1, align 32 | ||
| %offset = add i64 %iv, 1024 | ||
| %a2 = getelementptr i64, ptr %p, i64 %offset | ||
| store i64 %v, ptr %a2, align 32 | ||
| %iv.next = add i64 %iv, 1 | ||
| %cmp = icmp ne i64 %iv, 3001 | ||
| br i1 %cmp, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| define void @non-power-2-storeloadforward(ptr %A) { | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ; CHECK-LABEL: 'non-power-2-storeloadforward' | ||
| ; CHECK-NEXT: for.body: | ||
| ; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop | ||
| ; CHECK-NEXT: Backward loop carried data dependence that prevents store-to-load forwarding. | ||
| ; CHECK-NEXT: Dependences: | ||
| ; CHECK-NEXT: Forward: | ||
| ; CHECK-NEXT: %3 = load i32, ptr %arrayidx2, align 4 -> | ||
| ; CHECK-NEXT: store i32 %add3, ptr %arrayidx5, align 4 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: BackwardVectorizableButPreventsForwarding: | ||
| ; CHECK-NEXT: %1 = load i32, ptr %arrayidx, align 4 -> | ||
| ; CHECK-NEXT: store i32 %add3, ptr %arrayidx5, align 4 | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Run-time memory checks: | ||
| ; CHECK-NEXT: Grouped accesses: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop. | ||
| ; CHECK-NEXT: SCEV assumptions: | ||
| ; CHECK-EMPTY: | ||
| ; CHECK-NEXT: Expressions re-written: | ||
| ; | ||
| entry: | ||
| br label %for.body | ||
|
|
||
| for.body: | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| %iv = phi i64 [ 16, %entry ], [ %iv.next, %for.body ] | ||
| %0 = add nsw i64 %iv, -3 | ||
| %arrayidx = getelementptr inbounds i32, ptr %A, i64 %0 | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| %1 = load i32, ptr %arrayidx, align 4 | ||
| %2 = add nsw i64 %iv, 4 | ||
| %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %2 | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| %3 = load i32, ptr %arrayidx2, align 4 | ||
| %add3 = add nsw i32 %3, %1 | ||
| %arrayidx5 = getelementptr inbounds i32, ptr %A, i64 %iv | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| store i32 %add3, ptr %arrayidx5, align 4 | ||
| %iv.next = add i64 %iv, 1 | ||
| %lftr.wideiv = trunc i64 %iv.next to i32 | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| %exitcond = icmp ne i32 %lftr.wideiv, 128 | ||
| br i1 %exitcond, label %for.body, label %for.end | ||
|
|
||
| for.end: | ||
alexey-bataev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ret void | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.