-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Simplifiy sdiv -X, X
into X == INT_MIN ? 1 : -1
#71768
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
203b618
[InstCombine] Simplifiy sdiv -X, X into X == INT_MIN ? 1 : -1
Z572 71b8239
fixup! [InstCombine] Simplifiy sdiv -X, X into X == INT_MIN ? 1 : -1
Z572 62855d1
fixup! fixup! [InstCombine] Simplifiy sdiv -X, X into X == INT_MIN ? …
Z572 03c0c9c
fixup! fixup! fixup! [InstCombine] Simplifiy sdiv -X, X into X == INT…
Z572 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 |
---|---|---|
|
@@ -1432,6 +1432,88 @@ define <2 x i8> @sdiv_sdiv_mul_nsw(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { | |
ret <2 x i8> %r | ||
} | ||
|
||
define i32 @sdiv_sub1(i32 %arg) { | ||
; CHECK-LABEL: @sdiv_sub1( | ||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[ARG:%.*]], -2147483648 | ||
; CHECK-NEXT: [[DIV:%.*]] = select i1 [[TMP1]], i32 1, i32 -1 | ||
; CHECK-NEXT: ret i32 [[DIV]] | ||
; | ||
%neg = sub i32 0, %arg | ||
%div = sdiv i32 %neg, %arg | ||
ret i32 %div | ||
} | ||
|
||
define i32 @sdiv_sub2(i32 %arg) { | ||
; CHECK-LABEL: @sdiv_sub2( | ||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[ARG:%.*]], -2147483648 | ||
; CHECK-NEXT: [[DIV:%.*]] = select i1 [[TMP1]], i32 1, i32 -1 | ||
; CHECK-NEXT: ret i32 [[DIV]] | ||
; | ||
%neg = sub i32 0, %arg | ||
%div = sdiv i32 %arg, %neg | ||
ret i32 %div | ||
} | ||
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. Please also add a multi-use test (extra use of Please also test the case |
||
|
||
define i32 @sub_sdiv_multiuse(i32 %arg) { | ||
; CHECK-LABEL: @sub_sdiv_multiuse( | ||
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ARG:%.*]] | ||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[ARG]], -2147483648 | ||
; CHECK-NEXT: [[DIV:%.*]] = select i1 [[TMP1]], i32 1, i32 -1 | ||
; CHECK-NEXT: call void @use(i32 [[NEG]]) | ||
; CHECK-NEXT: ret i32 [[DIV]] | ||
; | ||
%neg = sub i32 0, %arg | ||
%div = sdiv i32 %arg, %neg | ||
call void @use(i32 %neg) | ||
ret i32 %div | ||
} | ||
|
||
define i32 @sdiv_sub_sub(i32 %x ,i32 %y) { | ||
; CHECK-LABEL: @sdiv_sub_sub( | ||
; CHECK-NEXT: [[S:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[S]], -2147483648 | ||
; CHECK-NEXT: [[D:%.*]] = select i1 [[TMP1]], i32 1, i32 -1 | ||
; CHECK-NEXT: ret i32 [[D]] | ||
; | ||
%s = sub i32 %x, %y | ||
%u = sub i32 %y, %x | ||
%d = sdiv i32 %s, %u | ||
ret i32 %d | ||
} | ||
|
||
define i32 @sdiv_mul_sub(i32 %x, i32 %y) { | ||
; CHECK-LABEL: @sdiv_mul_sub( | ||
; CHECK-NEXT: [[M:%.*]] = mul i32 [[Y:%.*]], [[X:%.*]] | ||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[M]], -2147483648 | ||
; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP1]], i32 1, i32 -1 | ||
; CHECK-NEXT: ret i32 [[R]] | ||
; | ||
%m = mul i32 %y, %x | ||
%d = sub i32 0, %m | ||
%r = sdiv i32 %d, %m | ||
ret i32 %r | ||
} | ||
|
||
define i32 @sdiv_mul_sub_nsw(i32 %x, i32 %y) { | ||
; CHECK-LABEL: @sdiv_mul_sub_nsw( | ||
; CHECK-NEXT: ret i32 -1 | ||
; | ||
%m = mul i32 %y, %x | ||
%n = sub nsw i32 0, %m | ||
%d = sdiv i32 %m, %n | ||
ret i32 %d | ||
} | ||
|
||
define i32 @sdiv_mul_nsw_sub_nsw(i32 %x, i32 %y) { | ||
; CHECK-LABEL: @sdiv_mul_nsw_sub_nsw( | ||
; CHECK-NEXT: ret i32 -1 | ||
; | ||
%m = mul nsw i32 %y, %x | ||
%n = sub nsw i32 0, %m | ||
%d = sdiv i32 %m, %n | ||
ret i32 %d | ||
} | ||
|
||
; exact propagates | ||
|
||
define i8 @sdiv_sdiv_mul_nsw_exact_exact(i8 %x, i8 %y, i8 %z) { | ||
|
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.