-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[AArch64]SIMD fpcvt codegen for rounding nodes #165546
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 6 commits
6377946
cec5513
d74cd15
3821797
0f90db6
ed50a6a
10877d2
21a0c8d
da01d0a
7e1c284
f085f44
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 |
|---|---|---|
|
|
@@ -6805,6 +6805,83 @@ defm : FPToIntegerPats<fp_to_uint, fp_to_uint_sat, fp_to_uint_sat_gi, ftrunc, "F | |
| defm : FPToIntegerPats<fp_to_sint, fp_to_sint_sat, fp_to_sint_sat_gi, fround, "FCVTAS">; | ||
| defm : FPToIntegerPats<fp_to_uint, fp_to_uint_sat, fp_to_uint_sat_gi, fround, "FCVTAU">; | ||
|
|
||
| // For global-isel we can use register classes to determine | ||
| // which FCVT instruction to use. | ||
| let Predicates = [HasFPRCVT] in { | ||
| def : Pat<(i64 (any_lround f16:$Rn)), | ||
| (FCVTASDHr f16:$Rn)>; | ||
| def : Pat<(i64 (any_llround f16:$Rn)), | ||
| (FCVTASDHr f16:$Rn)>; | ||
| def : Pat<(i64 (any_lround f32:$Rn)), | ||
|
||
| (FCVTASDSr f32:$Rn)>; | ||
| def : Pat<(i64 (any_llround f32:$Rn)), | ||
| (FCVTASDSr f32:$Rn)>; | ||
| } | ||
| def : Pat<(i64 (any_lround f64:$Rn)), | ||
| (FCVTASv1i64 f64:$Rn)>; | ||
| def : Pat<(i64 (any_llround f64:$Rn)), | ||
| (FCVTASv1i64 f64:$Rn)>; | ||
|
|
||
| let Predicates = [HasFPRCVT] in { | ||
| def : Pat<(f32 (bitconvert (i32 (any_lround f16:$Rn)))), | ||
| (FCVTASSHr f16:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lround f16:$Rn)))), | ||
| (FCVTASDHr f16:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llround f16:$Rn)))), | ||
| (FCVTASDHr f16:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lround f32:$Rn)))), | ||
| (FCVTASDSr f32:$Rn)>; | ||
| def : Pat<(f32 (bitconvert (i32 (any_lround f64:$Rn)))), | ||
| (FCVTASSDr f64:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llround f32:$Rn)))), | ||
| (FCVTASDSr f32:$Rn)>; | ||
| } | ||
| def : Pat<(f32 (bitconvert (i32 (any_lround f32:$Rn)))), | ||
| (FCVTASv1i32 f32:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lround f64:$Rn)))), | ||
| (FCVTASv1i64 f64:$Rn)>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llround f64:$Rn)))), | ||
| (FCVTASv1i64 f64:$Rn)>; | ||
|
|
||
| // For global-isel we can use register classes to determine | ||
| // which FCVT instruction to use. | ||
| let Predicates = [HasFPRCVT] in { | ||
| def : Pat<(i64 (any_lrint f16:$Rn)), | ||
| (FCVTZSDHr (FRINTXHr f16:$Rn))>; | ||
| def : Pat<(i64 (any_llrint f16:$Rn)), | ||
| (FCVTZSDHr (FRINTXHr f16:$Rn))>; | ||
| def : Pat<(i64 (any_lrint f32:$Rn)), | ||
| (FCVTZSDSr (FRINTXSr f32:$Rn))>; | ||
| def : Pat<(i64 (any_llrint f32:$Rn)), | ||
| (FCVTZSDSr (FRINTXSr f32:$Rn))>; | ||
| } | ||
| def : Pat<(i64 (any_lrint f64:$Rn)), | ||
| (FCVTZSv1i64 (FRINTXDr f64:$Rn))>; | ||
| def : Pat<(i64 (any_llrint f64:$Rn)), | ||
| (FCVTZSv1i64 (FRINTXDr f64:$Rn))>; | ||
|
|
||
| let Predicates = [HasFPRCVT] in { | ||
| def : Pat<(f32 (bitconvert (i32 (any_lrint f16:$Rn)))), | ||
| (FCVTZSSHr (FRINTXHr f16:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lrint f16:$Rn)))), | ||
| (FCVTZSDHr (FRINTXHr f16:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llrint f16:$Rn)))), | ||
| (FCVTZSDHr (FRINTXHr f16:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lrint f32:$Rn)))), | ||
| (FCVTZSDSr (FRINTXSr f32:$Rn))>; | ||
| def : Pat<(f32 (bitconvert (i32 (any_lrint f64:$Rn)))), | ||
| (FCVTZSSDr (FRINTXDr f64:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llrint f32:$Rn)))), | ||
| (FCVTZSDSr (FRINTXSr f32:$Rn))>; | ||
| } | ||
| def : Pat<(f32 (bitconvert (i32 (any_lrint f32:$Rn)))), | ||
| (FCVTZSv1i32 (FRINTXSr f32:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_lrint f64:$Rn)))), | ||
| (FCVTZSv1i64 (FRINTXDr f64:$Rn))>; | ||
| def : Pat<(f64 (bitconvert (i64 (any_llrint f64:$Rn)))), | ||
| (FCVTZSv1i64 (FRINTXDr f64:$Rn))>; | ||
|
|
||
|
|
||
| // f16 -> s16 conversions | ||
| let Predicates = [HasFullFP16] in { | ||
| def : Pat<(i16(fp_to_sint_sat_gi f16:$Rn)), (FCVTZSv1f16 f16:$Rn)>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc < %s -mtriple aarch64-unknown-unknown -mattr=+fprcvt,+fullfp16 | FileCheck %s --check-prefixes=CHECK | ||
|
|
||
| ; | ||
| ; (L/LL)Round experimental | ||
|
||
| ; | ||
|
|
||
| define float @lround_i32_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: lround_i32_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas s0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lround.i32.f16(half %x, metadata !"fpexcept.strict") | ||
| %sum = bitcast i32 %val to float | ||
| ret float %sum | ||
| } | ||
|
|
||
| define double @lround_i64_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: lround_i64_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lround.i64.f16(half %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @lround_i64_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: lround_i64_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lround.i64.f32(float %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define float @lround_i32_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: lround_i32_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas s0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lround.i32.f64(double %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i32 %val to float | ||
| ret float %bc | ||
| } | ||
|
|
||
| define float @lround_i32_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: lround_i32_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas s0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lround.i32.f32(float %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i32 %val to float | ||
| ret float %bc | ||
| } | ||
|
|
||
| define double @lround_i64_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: lround_i64_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lround.i64.f64(double %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @llround_i64_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: llround_i64_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llround.i64.f16(half %x, metadata !"fpexcept.strict") | ||
| %sum = bitcast i64 %val to double | ||
| ret double %sum | ||
| } | ||
|
|
||
| define double @llround_i64_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: llround_i64_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llround.i64.f32(float %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @llround_i64_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: llround_i64_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: fcvtas d0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llround.i64.f64(double %x, metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| ; | ||
| ; (L/LL)Rint experimental | ||
| ; | ||
|
|
||
| define float @lrint_i32_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: lrint_i32_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx h0, h0 | ||
| ; CHECK-NEXT: fcvtzs s0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lrint.i32.f16(half %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %sum = bitcast i32 %val to float | ||
| ret float %sum | ||
| } | ||
|
|
||
| define double @lrint_i64_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: lrint_i64_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx h0, h0 | ||
| ; CHECK-NEXT: fcvtzs d0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lrint.i53.f16(half %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @lrint_i64_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: lrint_i64_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx s0, s0 | ||
| ; CHECK-NEXT: fcvtzs d0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lrint.i64.f32(float %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define float @lrint_i32_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: lrint_i32_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx d0, d0 | ||
| ; CHECK-NEXT: fcvtzs s0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lrint.i32.f64(double %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i32 %val to float | ||
| ret float %bc | ||
| } | ||
|
|
||
| define float @lrint_i32_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: lrint_i32_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx s0, s0 | ||
| ; CHECK-NEXT: fcvtzs s0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i32 @llvm.experimental.constrained.lrint.i32.f32(float %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i32 %val to float | ||
| ret float %bc | ||
| } | ||
|
|
||
| define double @lrint_i64_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: lrint_i64_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx d0, d0 | ||
| ; CHECK-NEXT: fcvtzs d0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.lrint.i64.f64(double %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @llrint_i64_f16_simd_exp(half %x) { | ||
| ; CHECK-LABEL: llrint_i64_f16_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx h0, h0 | ||
| ; CHECK-NEXT: fcvtzs d0, h0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llrint.i64.f16(half %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %sum = bitcast i64 %val to double | ||
| ret double %sum | ||
| } | ||
|
|
||
| define double @llrint_i64_f32_simd_exp(float %x) { | ||
| ; CHECK-LABEL: llrint_i64_f32_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx s0, s0 | ||
| ; CHECK-NEXT: fcvtzs d0, s0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llrint.i64.f32(float %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
|
|
||
| define double @llrint_i64_f64_simd_exp(double %x) { | ||
| ; CHECK-LABEL: llrint_i64_f64_simd_exp: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: frintx d0, d0 | ||
| ; CHECK-NEXT: fcvtzs d0, d0 | ||
| ; CHECK-NEXT: ret | ||
| %val = call i64 @llvm.experimental.constrained.llrint.i64.f64(double %x, metadata !"round.tonearest", metadata !"fpexcept.strict") | ||
| %bc = bitcast i64 %val to double | ||
| ret double %bc | ||
| } | ||
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 am not sure if it will help, but maybe we could split the PR into patterns only for GlobalISel and another for the standard lowering/SelectionDAG?
I imagine that the ones from lines:
6810 till 6823
and
6848 till 6861
are only for GlobalISel while the other ones are for SelectionDAG
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.
Yes all the patterns without bitconvert node are for GlobalISel. May I ask what would be the value in splitting the patch ? As there is only couple of GlobalISel patterns added and the tests can be shared anyway, it makes sense to me to do it in one PR, but I can do that if you insist. The previous patches were also not split and it was fine.
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.
The main reason was to solve the issue raised by @arsenm about the complexity to review of the patch.