-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[InstCombine] simplify icmp pred x, ~x
#73990
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
Changes from all commits
ea9f69f
0d681e7
e9aba12
11efb03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,6 +5,349 @@ declare void @llvm.assume(i1) | |||
| declare void @barrier() | ||||
| declare void @use.i8(i8) | ||||
|
|
||||
| ; Test case of X comp X^Neg_C, which have Transform to SLT. | ||||
| ; X s< X^Neg_C --> X s< 0 | ||||
| define i1 @src_slt(i8 %x) { | ||||
| ; CHECK-LABEL: @src_slt( | ||||
| ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0 | ||||
| ; CHECK-NEXT: ret i1 [[CMP]] | ||||
| ; | ||||
| %not = xor i8 %x, -1 | ||||
| %cmp = icmp slt i8 %x, %not | ||||
| ret i1 %cmp | ||||
| } | ||||
|
|
||||
| define <2 x i1> @src_slt_vec(<2 x i8> %x) { | ||||
| ; CHECK-LABEL: @src_slt_vec( | ||||
| ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer | ||||
| ; CHECK-NEXT: ret <2 x i1> [[CMP]] | ||||
| ; | ||||
| %not = xor <2 x i8> %x, <i8 -1, i8 -1> | ||||
| %cmp = icmp slt <2 x i8> %x, %not | ||||
| ret <2 x i1> %cmp | ||||
| } | ||||
|
|
||||
| ; X s<= X^Neg_C --> X s< 0 | ||||
| define i1 @src_sle(i8 %x) { | ||||
|
||||
| // icmp (X ^ Y_NonZero) u>= X --> icmp (X ^ Y_NonZero) u> X |
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.
@nikic I could not even imagine that!! thank you for let me know!
I don't sure that I exact understood what you say.
are you want to that I need to change tests so that tests are can tested as purpose as for now.
should I change the code shown in the link next time?
or I could move my codes position into that function foldICmpXorXX?
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.
@nikic maybe this problem solved after implemented code moved to foidIcmpXorXX. how do you think?
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.
This comment comment is not done. The tests still don't properly check the commuted case -- and it looks like the implementation doesn't handle the commuted case either. It would be probably be better to move the code inside foldICmpXorXX(), because that already has handling for the commutation.
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.
After #91185 you shouldn't need to change the tests anymore -- just make sure that the commuted ones actually do get folded.
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.
I feel like there are bit too many tests here for such a simple transform :) See https://llvm.org/docs/InstCombineContributorGuide.html#general-testing-considerations:
It's not necessary to have a variant of every test with -1 and -128. It's okay to have most tests with -1 and just one with -128.
Similarly, we don't need to have an i128 variant of every tests. It's again something where it's fine to test it just once.