-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -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() { | ||
|
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. Can you add this case to one of the existing shl tests
Contributor
Author
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. Will do! Thanks!
Contributor
Author
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. I couldn't find another IR test for legalising shifts. I found https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/AArch64/GlobalISel/legalize-shift.mir, though. Should I add the MIR here?
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/CodeGen/AArch64/shift.ll seems to have a -global-isel run line? |
||
| ; 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 | ||
| } | ||
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