-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SimplifyCFG] Simplify switch instruction that has duplicate arms #114262
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
Merged
Changes from 2 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
fbfa46a
[SimplifyCFG] precommit tests for simplify switch with duplicate arms
michaelmaitland 2db9f00
[SimplifyCFG] Simplify switch instruction that has duplicate arms
michaelmaitland 4e56067
fixup! respond to review
michaelmaitland 9e10655
fixup! refactor for general approach
michaelmaitland 64ddee6
fixup! move PHI checks
michaelmaitland c8eecb6
fixup! make it O(n)
michaelmaitland 9e9afc2
fixup! use successor BBs in hash
michaelmaitland ef1bc74
fixup! use hasNPredsOrMore for early exit capability
michaelmaitland 794d4e8
fixup! don't add to Cases if size() != 1 to improve performance
michaelmaitland 32b627f
fixup! precompute getIncomingValueForBlock
michaelmaitland 4190352
fixup! only support unconditional branches
michaelmaitland f04d67f
fixup! try improving getHashValue
michaelmaitland 4ca2777
fixup! nitty cleanup
michaelmaitland 28620df
fixup! don't reproccess map for same BB
michaelmaitland 9dcf124
fixup! avoid calls to getIncomingValueForBlock
michaelmaitland 41edd15
fixup! drop Seen vector since we no longer build phi map in loop
michaelmaitland 5c247db
fixup! respond to review
michaelmaitland c3a1361
fixup! some cleanup and add Seen checks
michaelmaitland b563080
fixup! try and avoid some resizes
michaelmaitland 67b3c80
fixup! presize PhiPredIVs based on first pass data
michaelmaitland 94ff86e
fixup! use reserve instead of resize
michaelmaitland c6a5e52
fixup! precompute incoming values from BB
michaelmaitland 241fef5
fixup! don't hash an empty set of values
michaelmaitland aa4cf43
fixup! add some comments
michaelmaitland 8153c4b
fixup! simplify getHashValue
michaelmaitland d1cd111
fixup! another attempt at fixing hashing
michaelmaitland 4949890
fixup! fix crashes
michaelmaitland e91253c
fixup~ Revert changes that precompute for getHashValue.
michaelmaitland d87ea1d
fixup! use SmallVector instead of vector
michaelmaitland be55920
fixup! update dom tree
michaelmaitland 085b048
fixup! use get/set Sucessor
michaelmaitland 3f0b020
fixup! avoid extra insert
michaelmaitland 3430a66
fixup! respond to review
michaelmaitland 852f3f0
fixup! respond to review
michaelmaitland 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
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,140 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s -check-prefix=SIMPLIFY-CFG | ||
michaelmaitland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ; RUN: opt < %s -O3 -S | FileCheck %s -check-prefix=O3 | ||
michaelmaitland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| define i32 @switch_all_duplicate_arms(i32 %0, i32 %1, i32 %2, i32 %3) { | ||
michaelmaitland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ; SIMPLIFY-CFG-LABEL: define i32 @switch_all_duplicate_arms( | ||
| ; SIMPLIFY-CFG-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]]) { | ||
| ; SIMPLIFY-CFG-NEXT: switch i32 [[TMP1]], label %[[BB6:.*]] [ | ||
| ; SIMPLIFY-CFG-NEXT: i32 0, label %[[BB5:.*]] | ||
| ; SIMPLIFY-CFG-NEXT: i32 1, label %[[BB5]] | ||
| ; SIMPLIFY-CFG-NEXT: ] | ||
| ; SIMPLIFY-CFG: [[BB5]]: | ||
| ; SIMPLIFY-CFG-NEXT: br label %[[BB6]] | ||
| ; SIMPLIFY-CFG: [[BB6]]: | ||
| ; SIMPLIFY-CFG-NEXT: [[TMP8:%.*]] = phi i32 [ [[TMP3]], [[TMP4:%.*]] ], [ [[TMP2]], %[[BB5]] ] | ||
| ; SIMPLIFY-CFG-NEXT: ret i32 [[TMP8]] | ||
| ; | ||
| ; O3-LABEL: define i32 @switch_all_duplicate_arms( | ||
| ; O3-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { | ||
| ; O3-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[TMP1]], 2 | ||
| ; O3-NEXT: [[TMP8:%.*]] = select i1 [[SWITCH]], i32 [[TMP2]], i32 [[TMP3]] | ||
| ; O3-NEXT: ret i32 [[TMP8]] | ||
| ; | ||
| switch i32 %1, label %7 [ | ||
| i32 0, label %5 | ||
| i32 1, label %6 | ||
| ] | ||
|
|
||
| 5: | ||
| br label %7 | ||
|
|
||
| 6: | ||
| br label %7 | ||
|
|
||
| 7: | ||
| %8 = phi i32 [ %3, %4 ], [ %2, %6 ], [ %2, %5 ] | ||
| ret i32 %8 | ||
| } | ||
|
|
||
| define i32 @switch_some_duplicate_arms(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) { | ||
| ; SIMPLIFY-CFG-LABEL: define i32 @switch_some_duplicate_arms( | ||
| ; SIMPLIFY-CFG-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]], i32 [[TMP4:%.*]]) { | ||
| ; SIMPLIFY-CFG-NEXT: switch i32 [[TMP1]], label %[[BB8:.*]] [ | ||
| ; SIMPLIFY-CFG-NEXT: i32 0, label %[[BB6:.*]] | ||
| ; SIMPLIFY-CFG-NEXT: i32 1, label %[[BB6]] | ||
| ; SIMPLIFY-CFG-NEXT: i32 2, label %[[BB7:.*]] | ||
| ; SIMPLIFY-CFG-NEXT: ] | ||
| ; SIMPLIFY-CFG: [[BB6]]: | ||
| ; SIMPLIFY-CFG-NEXT: br label %[[BB8]] | ||
| ; SIMPLIFY-CFG: [[BB7]]: | ||
| ; SIMPLIFY-CFG-NEXT: br label %[[BB8]] | ||
| ; SIMPLIFY-CFG: [[BB8]]: | ||
| ; SIMPLIFY-CFG-NEXT: [[TMP10:%.*]] = phi i32 [ [[TMP3]], [[TMP5:%.*]] ], [ [[TMP4]], %[[BB7]] ], [ [[TMP2]], %[[BB6]] ] | ||
| ; SIMPLIFY-CFG-NEXT: ret i32 [[TMP10]] | ||
| ; | ||
| ; O3-LABEL: define i32 @switch_some_duplicate_arms( | ||
| ; O3-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]], i32 [[TMP4:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
| ; O3-NEXT: switch i32 [[TMP1]], label %[[BB8:.*]] [ | ||
| ; O3-NEXT: i32 0, label %[[BB6:.*]] | ||
| ; O3-NEXT: i32 1, label %[[BB6]] | ||
| ; O3-NEXT: i32 2, label %[[BB7:.*]] | ||
| ; O3-NEXT: ] | ||
| ; O3: [[BB6]]: | ||
| ; O3-NEXT: br label %[[BB8]] | ||
| ; O3: [[BB7]]: | ||
| ; O3-NEXT: br label %[[BB8]] | ||
| ; O3: [[BB8]]: | ||
| ; O3-NEXT: [[TMP10:%.*]] = phi i32 [ [[TMP3]], [[TMP5:%.*]] ], [ [[TMP4]], %[[BB7]] ], [ [[TMP2]], %[[BB6]] ] | ||
| ; O3-NEXT: ret i32 [[TMP10]] | ||
| ; | ||
| switch i32 %1, label %9 [ | ||
| i32 0, label %6 | ||
| i32 1, label %7 | ||
| i32 2, label %8 | ||
| ] | ||
|
|
||
| 6: | ||
| br label %9 | ||
|
|
||
| 7: | ||
| br label %9 | ||
|
|
||
| 8: | ||
| br label %9 | ||
|
|
||
| 9: | ||
| %10 = phi i32 [ %3, %5 ], [ %4, %8 ], [ %2, %7 ], [ %2, %6 ] | ||
| ret i32 %10 | ||
| } | ||
|
|
||
| define i32 @switch_duplicate_arms_multipred(i1 %0, i32 %1, i32 %2, i32 %3, i32 %4) { | ||
| ; SIMPLIFY-CFG-LABEL: define i32 @switch_duplicate_arms_multipred( | ||
| ; SIMPLIFY-CFG-SAME: i1 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]], i32 [[TMP4:%.*]]) { | ||
| ; SIMPLIFY-CFG-NEXT: br i1 [[TMP0]], label %[[BB6:.*]], label %[[BB7:.*]] | ||
| ; SIMPLIFY-CFG: [[BB6]]: | ||
| ; SIMPLIFY-CFG-NEXT: switch i32 [[TMP2]], label %[[BB9:.*]] [ | ||
| ; SIMPLIFY-CFG-NEXT: i32 0, label %[[BB7]] | ||
| ; SIMPLIFY-CFG-NEXT: i32 1, label %[[BB8:.*]] | ||
| ; SIMPLIFY-CFG-NEXT: ] | ||
| ; SIMPLIFY-CFG: [[BB7]]: | ||
| ; SIMPLIFY-CFG-NEXT: br label %[[BB9]] | ||
| ; SIMPLIFY-CFG: [[BB8]]: | ||
| ; SIMPLIFY-CFG-NEXT: br label %[[BB9]] | ||
| ; SIMPLIFY-CFG: [[BB9]]: | ||
| ; SIMPLIFY-CFG-NEXT: [[TMP10:%.*]] = phi i32 [ [[TMP4]], %[[BB6]] ], [ [[TMP3]], %[[BB8]] ], [ [[TMP3]], %[[BB7]] ] | ||
| ; SIMPLIFY-CFG-NEXT: ret i32 [[TMP10]] | ||
| ; | ||
| ; O3-LABEL: define i32 @switch_duplicate_arms_multipred( | ||
| ; O3-SAME: i1 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]], i32 [[TMP3:%.*]], i32 [[TMP4:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
| ; O3-NEXT: br i1 [[TMP0]], label %[[BB6:.*]], label %[[BB7:.*]] | ||
| ; O3: [[BB6]]: | ||
| ; O3-NEXT: switch i32 [[TMP2]], label %[[BB9:.*]] [ | ||
| ; O3-NEXT: i32 0, label %[[BB7]] | ||
| ; O3-NEXT: i32 1, label %[[BB8:.*]] | ||
| ; O3-NEXT: ] | ||
| ; O3: [[BB7]]: | ||
| ; O3-NEXT: br label %[[BB9]] | ||
| ; O3: [[BB8]]: | ||
| ; O3-NEXT: br label %[[BB9]] | ||
| ; O3: [[BB9]]: | ||
| ; O3-NEXT: [[TMP10:%.*]] = phi i32 [ [[TMP4]], %[[BB6]] ], [ [[TMP3]], %[[BB8]] ], [ [[TMP3]], %[[BB7]] ] | ||
| ; O3-NEXT: ret i32 [[TMP10]] | ||
| ; | ||
| br i1 %0, label %6, label %7 | ||
| 6: | ||
| switch i32 %2, label %9 [ | ||
| i32 0, label %7 | ||
| i32 1, label %8 | ||
| ] | ||
|
|
||
| 7: | ||
| br label %9 | ||
|
|
||
| 8: | ||
| br label %9 | ||
|
|
||
| 9: | ||
| %10 = phi i32 [ %4, %6 ], [ %3, %8 ], [ %3, %7 ] | ||
| ret i32 %10 | ||
| } | ||
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.