-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SCEV] forgetValue: support (with-overflow-inst op0, op1) #98015
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
nikic
merged 4 commits into
llvm:main
from
v01dXYZ:97586-scev-bug-forgetvalue-with-overflow-inst
Jul 9, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d82945c
(Draft) [SCEV] forgetValue: support (extractvalue 0, (with-overflow-i…
f08d687
[LoopUnroll] pre-commit test for LoopPeel SCEV invalidation
612b1cd
[LoopUnroll] test for LoopPeel SCEV invalidation
3ef1bf6
[SCEV] visitAndClearUsers support WithOverflowInst more simply
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
71 changes: 71 additions & 0 deletions
71
llvm/test/Transforms/LoopUnroll/peel-loop-scev-invalidate-with-overflow-inst.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,71 @@ | ||
; RUN: opt < %s -S -passes='print<scalar-evolution>,loop-unroll<peeling;full-unroll-max=0>,print<scalar-evolution>' 2>&1 | FileCheck %s | ||
; | ||
; This test ensures that (extractvalue 0 (with-overflow-inst op0, op1)) | ||
; is invalidated by LoopPeel when the operands of with-overflow-inst | ||
; are changed. | ||
; | ||
; In the following case, LoopPeel modifies the CFG into another one | ||
; with %bb7 not dominating %bb2 and %bb3 although %extractvalue is | ||
; still the step for the %bb3 loop. %call has been modified and uses | ||
; different operands but the SCEV value for %extractvalue has not been | ||
; invalidated and still refers to %load in its SCEV operands | ||
; (SCEV(%extractvalue) := -2 + -2 * %load). | ||
; | ||
; When LoopUnroll tries to compute the SCEV for the %bb3 Phi, the | ||
; stale data for %extractvalue is used whereas %load is not available | ||
; in %bb3 which is wrong. | ||
; | ||
; for more details and nice pictures: https://github.com/llvm/llvm-project/issues/97586 | ||
; | ||
; Although the reason for the bug was in forgetValue, it is still relevant to | ||
; test if LoopPeel invalidates %extractvalue after changing %call. | ||
; | ||
; forgetValue only walks the users, so calling it on the IV Phis does not | ||
; invalidate %extractvalue (thus forgetLoop does not invalidate it too). | ||
; It has to be done by LoopPeel itself. | ||
|
||
|
||
define void @loop_peeling_smul_with_overflow() { | ||
; before loop-unroll | ||
; CHECK: Classifying expressions for: @loop_peeling_smul_with_overflow | ||
; CHECK: %extractvalue = extractvalue { i32, i1 } %call, 0 | ||
; CHECK-NEXT: --> (-2 + (-2 * %load)) | ||
; CHECK: %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ] | ||
; CHECK-NEXT: --> {0,+,(-2 + (-2 * %load))}<nuw><nsw><%bb3> | ||
; after loop-unroll | ||
; CHECK: Classifying expressions for: @loop_peeling_smul_with_overflow | ||
; CHECK: %extractvalue = extractvalue { i32, i1 } %call, 0 | ||
; CHECK-NEXT: --> (-2 * %add8.lcssa) | ||
; CHECK: %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ] | ||
; CHECK-NEXT: --> {0,+,(-2 * %add8.lcssa)}<nuw><nsw><%bb3> | ||
; | ||
bb: | ||
br label %bb1 | ||
|
||
bb1: ; preds = %bb3, %bb | ||
%phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ] | ||
br label %bb5 | ||
|
||
bb2: ; preds = %bb7 | ||
%call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2) | ||
%extractvalue = extractvalue { i32, i1 } %call, 0 | ||
br label %bb3 | ||
|
||
bb3: ; preds = %bb3, %bb2 | ||
%phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ] | ||
%add = add i32 %extractvalue, %phi4 | ||
br i1 false, label %bb3, label %bb1 | ||
|
||
bb5: ; preds = %bb7, %bb1 | ||
%phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ] | ||
%icmp = icmp eq i32 %phi, 0 | ||
br i1 %icmp, label %bb9, label %bb7 | ||
|
||
bb7: ; preds = %bb5 | ||
%load = load i32, ptr addrspace(1) null, align 4 | ||
%add8 = add i32 %load, 1 | ||
br i1 false, label %bb2, label %bb5 | ||
|
||
bb9: ; preds = %bb5 | ||
ret void | ||
} |
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
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.