-
Notifications
You must be signed in to change notification settings - Fork 15k
[SCEV] Fix NSW flag propagation in getAddExpr #155267
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
Open
sebpop
wants to merge
2
commits into
llvm:main
Choose a base branch
from
sebpop:scev-getAddExpr-wrap-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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
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
45 changes: 45 additions & 0 deletions
45
llvm/test/Analysis/DependenceAnalysis/scev-nsw-flags-enable-analysis.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,45 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt < %s -disable-output "-passes=print<da>" -aa-pipeline=basic-aa 2>&1 | FileCheck %s | ||
|
|
||
| ; Test that SCEV NSW flag preservation enables dependence analysis to work | ||
| ; correctly. Previously, SCEV would lose NSW flags when combining AddRec | ||
| ; expressions from GEP operations, causing dependence analysis to incorrectly | ||
| ; classify expressions as "wrapping" and fail analysis. | ||
|
|
||
| define void @test_da_with_scev_flags(ptr %A) { | ||
| ; This test verifies that dependence analysis now correctly identifies | ||
| ; self-dependences when SCEV preserves NSW flags from GEP index computations. | ||
| ; CHECK-LABEL: 'test_da_with_scev_flags' | ||
| ; CHECK-NEXT: Src: %val = load i32, ptr %gep, align 4 --> Dst: %val = load i32, ptr %gep, align 4 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; CHECK-NEXT: Src: %val = load i32, ptr %gep, align 4 --> Dst: store i32 %val, ptr %gep, align 4 | ||
| ; CHECK-NEXT: da analyze - consistent anti [0|<]! | ||
| ; CHECK-NEXT: Src: store i32 %val, ptr %gep, align 4 --> Dst: store i32 %val, ptr %gep, align 4 | ||
| ; CHECK-NEXT: da analyze - none! | ||
| ; | ||
|
|
||
| entry: | ||
| br label %loop | ||
|
|
||
| loop: | ||
| %i = phi i64 [ 0, %entry ], [ %i.next, %loop ] | ||
|
|
||
| ; Create NSW-flagged index computation | ||
| %mul = mul nsw i64 %i, 3 | ||
| %sub = add nsw i64 %mul, -6 | ||
|
|
||
| ; GEP that should result in SCEV: {(-2424 + %A),+,1212}<nw> | ||
| ; The <nw> flag should prevent false "wrapping" detection in DA | ||
| %gep = getelementptr inbounds [100 x i32], ptr %A, i64 %sub, i64 %sub | ||
|
|
||
| ; Self-dependence: should be detected as "none" (no dependence) | ||
| %val = load i32, ptr %gep | ||
| store i32 %val, ptr %gep | ||
|
|
||
| %i.next = add nsw i64 %i, 1 | ||
| %cond = icmp ult i64 %i.next, 50 | ||
| br i1 %cond, label %loop, label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the logic here. Adding together two nsw addrecs doesn't necessarily result in an nsw addrec.