-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DAGCombiner] Handle type-promoted constants in UDIV lowering #169491
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
Open
SavchenkoValeriy
wants to merge
2
commits into
llvm:main
Choose a base branch
from
SavchenkoValeriy:vector-udiv-by-const-lowering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−62
Open
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
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,41 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s | ||
|
|
||
| ; This test verifies that udiv by constant works correctly even when type | ||
| ; legalization promotes constant operands (e.g., i16 -> i32 in BUILD_VECTOR). | ||
| ; This is a regression test for a bug where v16i16 would be split into two | ||
| ; v8i16 operations during legalization, the i16 constants would be promoted | ||
| ; to i32, and then the second DAGCombine round would fail to recognize the | ||
| ; promoted constants when trying to convert udiv into mul+shift. | ||
|
|
||
| define <8 x i16> @udiv_v8i16_by_255(<8 x i16> %x) { | ||
| ; CHECK-LABEL: udiv_v8i16_by_255: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: mov w8, #32897 // =0x8081 | ||
| ; CHECK-NEXT: dup v1.8h, w8 | ||
| ; CHECK-NEXT: umull2 v2.4s, v0.8h, v1.8h | ||
| ; CHECK-NEXT: umull v0.4s, v0.4h, v1.4h | ||
| ; CHECK-NEXT: uzp2 v0.8h, v0.8h, v2.8h | ||
| ; CHECK-NEXT: ushr v0.8h, v0.8h, #7 | ||
| ; CHECK-NEXT: ret | ||
| %div = udiv <8 x i16> %x, splat (i16 255) | ||
| ret <8 x i16> %div | ||
| } | ||
|
|
||
| define <16 x i16> @udiv_v16i16_by_255(<16 x i16> %x) { | ||
| ; CHECK-LABEL: udiv_v16i16_by_255: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: mov w8, #32897 // =0x8081 | ||
| ; CHECK-NEXT: dup v2.8h, w8 | ||
| ; CHECK-NEXT: umull2 v3.4s, v0.8h, v2.8h | ||
| ; CHECK-NEXT: umull v0.4s, v0.4h, v2.4h | ||
| ; CHECK-NEXT: umull2 v4.4s, v1.8h, v2.8h | ||
| ; CHECK-NEXT: umull v1.4s, v1.4h, v2.4h | ||
| ; CHECK-NEXT: uzp2 v0.8h, v0.8h, v3.8h | ||
| ; CHECK-NEXT: uzp2 v1.8h, v1.8h, v4.8h | ||
| ; CHECK-NEXT: ushr v0.8h, v0.8h, #7 | ||
| ; CHECK-NEXT: ushr v1.8h, v1.8h, #7 | ||
| ; CHECK-NEXT: ret | ||
| %div = udiv <16 x i16> %x, splat (i16 255) | ||
| ret <16 x i16> %div | ||
| } | ||
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.
I don't understand why this is an issue for an example this trivial. I would expect this combine would fire in the pre-type-legalization combiner before the vector elements are promoted?
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 example was working correctly.
8 x i16is legal on AArch64 and gets lowered properly. For the16 x i16case, we don't do it because it's not legal, promote i16 constant and split it into two vectorudivs in type legalization, and then go to the combiner.