-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[InstCombine] Try the flipped strictness of predicate in foldICmpShlConstant
#92773
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
4 commits
Select commit
Hold shift + click to select a range
fa36954
[InstCombine] Add pre-commit tests. NFC.
dtcxzyw 91faa84
[InstCombine] Try the flipped strictness of predicate in `foldICmpShl…
dtcxzyw bba9b38
[InstCombine] Address review comments.
dtcxzyw c28db82
[InstCombine] Simplify code. NFC.
dtcxzyw 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 |
---|---|---|
|
@@ -5198,3 +5198,100 @@ define i1 @icmp_freeze_sext(i16 %x, i16 %y) { | |
%cmp2 = icmp uge i16 %ext.fr, %y | ||
ret i1 %cmp2 | ||
} | ||
|
||
define i1 @test_icmp_shl(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl( | ||
; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[X:%.*]] to i32 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[TMP1]], 3 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl i64 %x, 32 | ||
%cmp = icmp ult i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_multiuse(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_multiuse( | ||
; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[X:%.*]], 32 | ||
; CHECK-NEXT: call void @use_i64(i64 [[SHL]]) | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[SHL]], 8589934593 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl i64 %x, 32 | ||
call void @use_i64(i64 %shl) | ||
%cmp = icmp ult i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_illegal_length(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_illegal_length( | ||
; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[X:%.*]], 31 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[SHL]], 8589934593 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl i64 %x, 31 | ||
%cmp = icmp ult i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_invalid_rhsc(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_invalid_rhsc( | ||
; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[X:%.*]], 32 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[SHL]], 8589934595 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl i64 %x, 32 | ||
%cmp = icmp ult i64 %shl, 8589934595 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_nuw(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_nuw( | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 3 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl nuw i64 %x, 32 | ||
%cmp = icmp ult i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_nsw(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_nsw( | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 3 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl nsw i64 %x, 32 | ||
%cmp = icmp ult i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) { | ||
; CHECK-LABEL: @test_icmp_shl_vec( | ||
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[X:%.*]] to <2 x i32> | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[TMP1]], <i32 3, i32 3> | ||
; CHECK-NEXT: ret <2 x i1> [[CMP]] | ||
; | ||
%shl = shl <2 x i64> %x, splat(i64 32) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't know about the |
||
%cmp = icmp ult <2 x i64> %shl, splat(i64 8589934593) | ||
ret <2 x i1> %cmp | ||
} | ||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
define i1 @test_icmp_shl_eq(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_eq( | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
%shl = shl i64 %x, 32 | ||
%cmp = icmp eq i64 %shl, 8589934593 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_icmp_shl_sgt(i64 %x) { | ||
; CHECK-LABEL: @test_icmp_shl_sgt( | ||
; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[X:%.*]] to i32 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP1]], 1 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%shl = shl i64 %x, 32 | ||
%cmp = icmp sgt i64 %shl, 8589934591 | ||
ret i1 %cmp | ||
} |
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.
To account for Vec types should construct
ShType->getWithNewBitWidth(TypeBits - Amt)
and use that +ShType
for this check.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.
#92773 (comment)
It breaks some vec tests.