-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[AArch64][GlobalISel] Don't crash when legalising vector G_SHL #168848
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7683b54
[AArch64][GlobalISel] Don't crash when legalising vector G_SHL
cofibrant 92db3f7
Modify handling of `G_*SH*` opcodes in `LegalizerHelper::moreElements…
cofibrant 8e7ad65
Relocate test case
cofibrant 0425039
Make sure the test case won't be optimised out
cofibrant 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
29 changes: 29 additions & 0 deletions
29
llvm/test/CodeGen/AArch64/GlobalISel/legalize-shl-crash.ll
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,29 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: llc -global-isel -o - %s | FileCheck %s | ||
|
|
||
| target triple = "aarch64-unknown-unknown" | ||
|
|
||
| ; Check we don't crash here. | ||
|
|
||
| define <2 x i8> @test() { | ||
cofibrant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ; CHECK-LABEL: test: | ||
| ; CHECK: // %bb.0: // %entry | ||
| ; CHECK-NEXT: mov w8, #1 // =0x1 | ||
| ; CHECK-NEXT: mov w9, #0 // =0x0 | ||
| ; CHECK-NEXT: fmov s0, w8 | ||
| ; CHECK-NEXT: fmov s1, w9 | ||
| ; CHECK-NEXT: mov v0.b[1], w8 | ||
| ; CHECK-NEXT: mov v1.b[1], w9 | ||
| ; CHECK-NEXT: ushl v0.8b, v0.8b, v1.8b | ||
| ; CHECK-NEXT: umov w8, v0.b[0] | ||
| ; CHECK-NEXT: umov w9, v0.b[1] | ||
| ; CHECK-NEXT: fmov s0, w8 | ||
| ; CHECK-NEXT: mov v0.s[1], w9 | ||
| ; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0 | ||
| ; CHECK-NEXT: ret | ||
| entry: | ||
| %zeroes = zext <2 x i1> zeroinitializer to <2 x i32> | ||
| %ones = shl <2 x i32> splat (i32 1), %zeroes | ||
| %ones.trunc = trunc <2 x i32> %ones to <2 x i8> | ||
| ret <2 x i8> %ones.trunc | ||
| } | ||
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.
This seems fine but the rules should probably not be so fragile as to crash if you order them wrong
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.
Is there a code path where an action can fail with
UnableToLegalizebut we continue to apply other rules before returning to retry the failing rule after observing a change? If so I can add a check somewhere sensible for a more robust fix.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.
No, once we hit Unable the whole process will abort.
Uh oh!
There was an error while loading. Please reload this page.
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.
Ok, not sure I have a better fix... Basically the action responsible for padding vectors with more undef elements only accepts a single type to expand to, and when applied to binary operations naïvely uses this type for both input operands:
llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Lines 6688 to 6697 in 59ed6df
In other words, it assumes the inputs already agree on their scalar type. One option, I suppose, would be to have this code infer the number of elements from
MoreTy, but inherit the scalar element types from each operand for each call tomoreElementsVector*(). What 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.
We probably should have validation that the reported rule makes sense for the given operation as part of the rule parsing. The failure ideally wouldn't be deferred all the way to the application