-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[SimplifyCFG][Local] Redirect other phi values from BB to Succ except commom preds #166390
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
Camsyn
wants to merge
11
commits into
llvm:main
Choose a base branch
from
Camsyn:fix-regr-jump-threading
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
149ff26
Add tests before commit
Camsyn 91e69c2
[JumpThread][Local] Redirect phi values between BB and Succ with >1 c…
Camsyn 3649a41
Regenerate the tests after commit
Camsyn 1fb0bfe
Make formatter happy
Camsyn 53396de
Address review comment
Camsyn 9d3b709
Add some new tests
Camsyn de9cf0d
Regenerate the test cases
Camsyn 876f598
Handle case that all preds are the same common pred
Camsyn dfb3514
Add new testcase
Camsyn 39ec0c6
Regenerate the tests
Camsyn 4f64ddf
Fix comments
Camsyn 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
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,165 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
| ; RUN: opt -S -passes=jump-threading < %s | FileCheck %s | ||
|
|
||
| ; Jump threading would generate an intermediate BB `foo.thread` uncond to `succ`, | ||
| ; with preds case0, case1, and case2. | ||
| ; Theoretically, path case1/case0 -> foo.thread -> succ -> exit can be folded into case1/case0 -> exit. | ||
|
|
||
| define i64 @bar(i64 %0, i1 %1, i64 %num) { | ||
| ; CHECK-LABEL: @bar( | ||
| ; CHECK-NEXT: switch i64 [[TMP0:%.*]], label [[EXIT2:%.*]] [ | ||
| ; CHECK-NEXT: i64 0, label [[CASE0:%.*]] | ||
| ; CHECK-NEXT: i64 1, label [[CASE1:%.*]] | ||
| ; CHECK-NEXT: i64 2, label [[CASE2:%.*]] | ||
| ; CHECK-NEXT: ] | ||
| ; CHECK: case0: | ||
| ; CHECK-NEXT: br i1 [[TMP1:%.*]], label [[SUCC:%.*]], label [[FOO_THREAD:%.*]] | ||
| ; CHECK: case1: | ||
| ; CHECK-NEXT: br i1 [[TMP1]], label [[SUCC]], label [[FOO_THREAD]] | ||
| ; CHECK: case2: | ||
| ; CHECK-NEXT: br i1 [[TMP1]], label [[EXIT2]], label [[EXIT2]] | ||
| ; CHECK: succ: | ||
| ; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[NUM:%.*]], [[CASE1]] ], [ [[NUM]], [[CASE0]] ] | ||
| ; CHECK-NEXT: [[COND2:%.*]] = icmp eq i64 [[PHI2]], 0 | ||
| ; CHECK-NEXT: br i1 [[COND2]], label [[FOO_THREAD]], label [[EXIT2]] | ||
| ; CHECK: exit: | ||
| ; CHECK-NEXT: [[PHI25:%.*]] = phi i64 [ [[PHI2]], [[SUCC]] ], [ 0, [[CASE1]] ], [ 0, [[CASE0]] ] | ||
| ; CHECK-NEXT: call void @foo() | ||
| ; CHECK-NEXT: ret i64 [[PHI25]] | ||
| ; CHECK: exit2: | ||
| ; CHECK-NEXT: ret i64 0 | ||
| ; | ||
| switch i64 %0, label %foo [ | ||
| i64 0, label %case0 | ||
| i64 1, label %case1 | ||
| i64 2, label %case2 | ||
| ] | ||
|
|
||
| case0: ; preds = %2 | ||
| br i1 %1, label %succ, label %foo | ||
|
|
||
| case1: ; preds = %2 | ||
| br i1 %1, label %succ, label %foo | ||
|
|
||
| case2: | ||
| br i1 %1, label %exit2, label %foo | ||
|
|
||
| foo: ; preds = %case1, %case0, %2 | ||
| %phi1 = phi i64 [ 0, %case0 ], [ 0, %case1 ], [ 1, %case2 ], [ 10, %2 ] | ||
| %cond1 = icmp ult i64 %phi1, 2 | ||
| br i1 %cond1, label %succ, label %exit2 | ||
|
|
||
| succ: ; preds = %foo, %case1, %case0 | ||
| %phi2 = phi i64 [ %phi1, %foo ], [ %num, %case1 ], [ %num, %case0 ] | ||
| %cond2 = icmp eq i64 %phi2, 0 | ||
| br i1 %cond2, label %exit, label %exit2 | ||
|
|
||
| exit: | ||
| call void @foo() | ||
| ret i64 %phi2 | ||
|
|
||
| exit2: | ||
| ret i64 0 | ||
| } | ||
|
|
||
| define i64 @multicase(i64 %0, i1 %1, i64 %num) { | ||
| ; CHECK-LABEL: @multicase( | ||
| ; CHECK-NEXT: entry: | ||
| ; CHECK-NEXT: switch i64 [[TMP0:%.*]], label [[DEFAULT:%.*]] [ | ||
| ; CHECK-NEXT: i64 0, label [[FOO:%.*]] | ||
| ; CHECK-NEXT: i64 1, label [[FOO]] | ||
| ; CHECK-NEXT: i64 2, label [[SUCC:%.*]] | ||
| ; CHECK-NEXT: i64 3, label [[SUCC]] | ||
| ; CHECK-NEXT: ] | ||
| ; CHECK: succ: | ||
| ; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[NUM:%.*]], [[ENTRY:%.*]] ], [ [[NUM]], [[ENTRY]] ] | ||
| ; CHECK-NEXT: [[COND2:%.*]] = icmp eq i64 [[PHI2]], 0 | ||
| ; CHECK-NEXT: br i1 [[COND2]], label [[FOO]], label [[DEFAULT]] | ||
| ; CHECK: exit: | ||
| ; CHECK-NEXT: [[PHI23:%.*]] = phi i64 [ [[PHI2]], [[SUCC]] ], [ 0, [[ENTRY]] ], [ 0, [[ENTRY]] ] | ||
| ; CHECK-NEXT: call void @foo() | ||
| ; CHECK-NEXT: ret i64 [[PHI23]] | ||
| ; CHECK: exit2: | ||
| ; CHECK-NEXT: ret i64 0 | ||
| ; | ||
| entry: | ||
| switch i64 %0, label %default [ | ||
| i64 0, label %foo | ||
| i64 1, label %foo | ||
| i64 2, label %succ | ||
| i64 3, label %succ | ||
| ] | ||
|
|
||
| default: ; preds = %entry | ||
| br label %foo | ||
|
|
||
| foo: ; preds = %default, %entry, %entry | ||
| %phi1 = phi i64 [ 0, %entry ], [ 0, %entry ], [ 1, %default ] | ||
| %cond1 = icmp ult i64 %phi1, 2 | ||
| br i1 %cond1, label %succ, label %exit2 | ||
|
|
||
| succ: ; preds = %foo, %entry, %entry | ||
| %phi2 = phi i64 [ %num, %entry ], [ %num, %entry ], [ %phi1, %foo ] | ||
| %cond2 = icmp eq i64 %phi2, 0 | ||
| br i1 %cond2, label %exit, label %exit2 | ||
|
|
||
| exit: ; preds = %succ | ||
| call void @foo() | ||
| ret i64 %phi2 | ||
|
|
||
| exit2: ; preds = %succ, %foo | ||
| ret i64 0 | ||
| } | ||
|
|
||
| define i64 @multicase2(i64 %0, i1 %1, i64 %num) { | ||
| ; CHECK-LABEL: @multicase2( | ||
| ; CHECK-NEXT: entry: | ||
| ; CHECK-NEXT: switch i64 [[TMP0:%.*]], label [[UNREACHABLE:%.*]] [ | ||
| ; CHECK-NEXT: i64 0, label [[EXIT:%.*]] | ||
| ; CHECK-NEXT: i64 1, label [[EXIT]] | ||
| ; CHECK-NEXT: i64 2, label [[SUCC:%.*]] | ||
| ; CHECK-NEXT: i64 3, label [[SUCC]] | ||
| ; CHECK-NEXT: ] | ||
| ; CHECK: unreachable: | ||
| ; CHECK-NEXT: unreachable | ||
| ; CHECK: succ: | ||
| ; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ [[NUM:%.*]], [[ENTRY:%.*]] ], [ [[NUM]], [[ENTRY]] ] | ||
| ; CHECK-NEXT: [[COND2:%.*]] = icmp eq i64 [[PHI2]], 0 | ||
| ; CHECK-NEXT: br i1 [[COND2]], label [[EXIT]], label [[EXIT2:%.*]] | ||
| ; CHECK: exit: | ||
| ; CHECK-NEXT: [[PHI23:%.*]] = phi i64 [ [[PHI2]], [[SUCC]] ], [ 0, [[ENTRY]] ], [ 0, [[ENTRY]] ] | ||
| ; CHECK-NEXT: call void @foo() | ||
| ; CHECK-NEXT: ret i64 [[PHI23]] | ||
| ; CHECK: exit2: | ||
| ; CHECK-NEXT: ret i64 0 | ||
| ; | ||
| entry: | ||
| switch i64 %0, label %unreachable [ | ||
| i64 0, label %foo | ||
| i64 1, label %foo | ||
| i64 2, label %succ | ||
| i64 3, label %succ | ||
| ] | ||
|
|
||
| unreachable: ; preds = %entry | ||
| unreachable | ||
|
|
||
| foo: ; preds = %entry, %entry | ||
| %phi1 = phi i64 [ 0, %entry ], [ 0, %entry ] | ||
| %cond1 = icmp ult i64 %phi1, 2 | ||
| br i1 %cond1, label %succ, label %exit2 | ||
|
|
||
| succ: ; preds = %foo, %entry, %entry | ||
| %phi2 = phi i64 [ %num, %entry ], [ %num, %entry ], [ %phi1, %foo ] | ||
| %cond2 = icmp eq i64 %phi2, 0 | ||
| br i1 %cond2, label %exit, label %exit2 | ||
|
|
||
| exit: ; preds = %succ | ||
| call void @foo() | ||
| ret i64 %phi2 | ||
|
|
||
| exit2: ; preds = %succ, %foo | ||
| ret i64 0 | ||
| } | ||
|
|
||
| declare void @foo() | ||
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.
Could you please add some tests with multiple common predecessors, where some of them are identical? Such as:
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh, this PR can eliminate the whole phis in bb if the common predecessors between bb and succ are the same 😀.
Please refer to 39ec0c6