-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[InstCombine] Canonicalize xor with disjoint ops to or disjoint #133139
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
Closed
Closed
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -1664,3 +1664,52 @@ entry: | |
| %or = or <2 x i32> %add, %c | ||
| ret <2 x i32> %or | ||
| } | ||
|
|
||
| declare i32 @callee() | ||
|
|
||
| define i32 @xor_disjoint() { | ||
| ; CHECK-LABEL: @xor_disjoint( | ||
| ; CHECK-NEXT: [[CALL1:%.*]] = call i32 @callee(), !range [[RNG0:![0-9]+]] | ||
| ; CHECK-NEXT: [[XOR:%.*]] = or disjoint i32 [[CALL1]], 4096 | ||
| ; CHECK-NEXT: ret i32 [[XOR]] | ||
| ; | ||
| %call1 = call i32 @callee(), !range !0 | ||
| %xor = xor i32 %call1, 4096 | ||
| ret i32 %xor | ||
| } | ||
|
|
||
| define i32 @xor_disjoint2() { | ||
| ; CHECK-LABEL: @xor_disjoint2( | ||
| ; CHECK-NEXT: [[CALL1:%.*]] = call i32 @callee(), !range [[RNG1:![0-9]+]] | ||
| ; CHECK-NEXT: [[XOR:%.*]] = or disjoint i32 [[CALL1]], 512 | ||
| ; CHECK-NEXT: ret i32 [[XOR]] | ||
| ; | ||
| %call1 = call i32 @callee(), !range !1 | ||
| %xor = xor i32 %call1, 512 | ||
| ret i32 %xor | ||
| } | ||
|
|
||
| define i32 @xor_non_disjoint() { | ||
| ; CHECK-LABEL: @xor_non_disjoint( | ||
| ; CHECK-NEXT: [[CALL1:%.*]] = call i32 @callee(), !range [[RNG0]] | ||
| ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[CALL1]], 1024 | ||
| ; CHECK-NEXT: ret i32 [[XOR]] | ||
| ; | ||
| %call1 = call i32 @callee(), !range !0 | ||
| %xor = xor i32 %call1, 1024 | ||
| ret i32 %xor | ||
| } | ||
|
|
||
| define i32 @xor_non_disjoint2() { | ||
| ; CHECK-LABEL: @xor_non_disjoint2( | ||
| ; CHECK-NEXT: [[CALL1:%.*]] = call i32 @callee(), !range [[RNG1]] | ||
| ; CHECK-NEXT: [[XOR:%.*]] = and i32 [[CALL1]], 511 | ||
| ; CHECK-NEXT: ret i32 [[XOR]] | ||
| ; | ||
| %call1 = call i32 @callee(), !range !1 | ||
| %xor = xor i32 %call1, 1024 | ||
| ret i32 %xor | ||
| } | ||
|
|
||
|
Contributor
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. Test a vector version. Also could use alive2 proof link |
||
| !0 = !{ i32 0, i32 2048 } | ||
| !1 = !{ i32 1024, i32 1536 } | ||
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.
Can try to short circuit the first operand query if the second is unknown