-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SimplifyCFG] Delete the unnecessary range check for small mask operation #65835
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 all commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -passes=simplifycfg --switch-to-lookup -S < %s | FileCheck %s | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
|
||
; https://alive2.llvm.org/ce/z/tuxLhJ | ||
define i1 @switch_lookup_with_small_i1(i64 %x) { | ||
; CHECK-LABEL: @switch_lookup_with_small_i1( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[AND:%.*]] = and i64 [[X:%.*]], 15 | ||
; CHECK-NEXT: [[SWITCH_CAST:%.*]] = trunc i64 [[AND]] to i16 | ||
; CHECK-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i16 [[SWITCH_CAST]], 1 | ||
; CHECK-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i16 1030, [[SWITCH_SHIFTAMT]] | ||
; CHECK-NEXT: [[SWITCH_MASKED:%.*]] = trunc i16 [[SWITCH_DOWNSHIFT]] to i1 | ||
; CHECK-NEXT: ret i1 [[SWITCH_MASKED]] | ||
; | ||
entry: | ||
%and = and i64 %x, 15 | ||
switch i64 %and, label %default [ | ||
i64 10, label %lor.end | ||
i64 1, label %lor.end | ||
i64 2, label %lor.end | ||
] | ||
|
||
default: ; preds = %entry | ||
br label %lor.end | ||
|
||
lor.end: ; preds = %entry, %entry, %entry, %default | ||
%0 = phi i1 [ true, %entry ], [ false, %default ], [ true, %entry ], [ true, %entry ] | ||
ret i1 %0 | ||
} | ||
vfdff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
; https://godbolt.org/z/sjbjorKon | ||
define i8 @switch_lookup_with_small_i8(i64 %x) { | ||
; CHECK-LABEL: @switch_lookup_with_small_i8( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[REM:%.*]] = urem i64 [[X:%.*]], 5 | ||
; CHECK-NEXT: [[SWITCH_CAST:%.*]] = trunc i64 [[REM]] to i40 | ||
; CHECK-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i40 [[SWITCH_CAST]], 8 | ||
; CHECK-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i40 460303, [[SWITCH_SHIFTAMT]] | ||
; CHECK-NEXT: [[SWITCH_MASKED:%.*]] = trunc i40 [[SWITCH_DOWNSHIFT]] to i8 | ||
; CHECK-NEXT: ret i8 [[SWITCH_MASKED]] | ||
; | ||
entry: | ||
%rem = urem i64 %x, 5 | ||
switch i64 %rem, label %default [ | ||
i64 0, label %sw.bb0 | ||
i64 1, label %sw.bb1 | ||
i64 2, label %sw.bb2 | ||
] | ||
|
||
sw.bb0: ; preds = %entry | ||
br label %lor.end | ||
|
||
sw.bb1: ; preds = %entry | ||
br label %lor.end | ||
|
||
sw.bb2: ; preds = %entry | ||
br label %lor.end | ||
|
||
default: ; preds = %entry | ||
br label %lor.end | ||
|
||
lor.end: | ||
%0 = phi i8 [ 15, %sw.bb0 ], [ 6, %sw.bb1 ], [ 7, %sw.bb2 ], [ 0, %default ] | ||
ret i8 %0 | ||
} | ||
|
||
; Negative test: Table size would not fit the register. | ||
define i8 @switch_lookup_with_small_i8_negative(i64 %x) { | ||
; CHECK-LABEL: @switch_lookup_with_small_i8_negative( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[REM:%.*]] = urem i64 [[X:%.*]], 9 | ||
; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i64 [[REM]], 3 | ||
; CHECK-NEXT: [[SWITCH_CAST:%.*]] = trunc i64 [[REM]] to i24 | ||
; CHECK-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i24 [[SWITCH_CAST]], 8 | ||
; CHECK-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i24 460303, [[SWITCH_SHIFTAMT]] | ||
; CHECK-NEXT: [[SWITCH_MASKED:%.*]] = trunc i24 [[SWITCH_DOWNSHIFT]] to i8 | ||
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i8 [[SWITCH_MASKED]], i8 0 | ||
; CHECK-NEXT: ret i8 [[TMP1]] | ||
; | ||
entry: | ||
%rem = urem i64 %x, 9 ; 9 * 8 = 72 > 64, not fit the register | ||
switch i64 %rem, label %default [ | ||
i64 0, label %sw.bb0 | ||
i64 1, label %sw.bb1 | ||
i64 2, label %sw.bb2 | ||
] | ||
|
||
sw.bb0: ; preds = %entry | ||
br label %lor.end | ||
|
||
sw.bb1: ; preds = %entry | ||
br label %lor.end | ||
|
||
sw.bb2: ; preds = %entry | ||
br label %lor.end | ||
|
||
default: ; preds = %entry | ||
br label %lor.end | ||
|
||
lor.end: | ||
%0 = phi i8 [ 15, %sw.bb0 ], [ 6, %sw.bb1 ], [ 7, %sw.bb2 ], [ 0, %default ] | ||
ret i8 %0 | ||
} |
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.