-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LoongArch] lower SCALAR_TO_VECTOR to INSERT_VECTOR_ELT #122863
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 5 commits
7e36c8d
d574316
6d36284
deae039
4bba81b
5cf9af0
a71a98f
948416e
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,60 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc --mtriple=loongarch64 --mattr=+lasx < %s | FileCheck %s | ||
|
|
||
| ;; Test scalar_to_vector expansion. | ||
|
|
||
| define <32 x i8> @scalar_to_32xi8(i8 %val) { | ||
| ; CHECK-LABEL: scalar_to_32xi8: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.b $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <32 x i8> poison, i8 %val, i32 0 | ||
| ret <32 x i8> %ret | ||
| } | ||
|
|
||
| define <16 x i16> @scalar_to_16xi16(i16 %val) { | ||
| ; CHECK-LABEL: scalar_to_16xi16: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.h $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <16 x i16> poison, i16 %val, i32 0 | ||
| ret <16 x i16> %ret | ||
| } | ||
|
|
||
| define <8 x i32> @scalar_to_8xi32(i32 %val) { | ||
| ; CHECK-LABEL: scalar_to_8xi32: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: xvinsgr2vr.w $xr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <8 x i32> poison, i32 %val, i32 0 | ||
| ret <8 x i32> %ret | ||
| } | ||
|
|
||
| define <4 x i64> @scalar_to_4xi64(i64 %val) { | ||
| ; CHECK-LABEL: scalar_to_4xi64: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: xvinsgr2vr.d $xr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <4 x i64> poison, i64 %val, i32 0 | ||
| ret <4 x i64> %ret | ||
| } | ||
|
|
||
| define <8 x float> @scalar_to_8xf32(float %val) { | ||
| ; CHECK-LABEL: scalar_to_8xf32: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: movfr2gr.s $a0, $fa0 | ||
| ; CHECK-NEXT: xvinsgr2vr.w $xr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <8 x float> poison, float %val, i32 0 | ||
| ret <8 x float> %ret | ||
| } | ||
|
|
||
| define <4 x double> @scalar_to_4xf64(double %val) { | ||
| ; CHECK-LABEL: scalar_to_4xf64: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: movfr2gr.d $a0, $fa0 | ||
| ; CHECK-NEXT: xvinsgr2vr.d $xr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <4 x double> poison, double %val, i32 0 | ||
| ret <4 x double> %ret | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s | ||
|
|
||
| ;; Test scalar_to_vector expansion. | ||
|
|
||
| define <16 x i8> @scalar_to_16xi8(i8 %val) { | ||
| ; CHECK-LABEL: scalar_to_16xi8: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.b $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <16 x i8> poison, i8 %val, i32 0 | ||
| ret <16 x i8> %ret | ||
| } | ||
|
|
||
| define <8 x i16> @scalar_to_8xi16(i16 %val) { | ||
| ; CHECK-LABEL: scalar_to_8xi16: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.h $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <8 x i16> poison, i16 %val, i32 0 | ||
| ret <8 x i16> %ret | ||
| } | ||
|
|
||
| define <4 x i32> @scalar_to_4xi32(i32 %val) { | ||
| ; CHECK-LABEL: scalar_to_4xi32: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.w $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <4 x i32> poison, i32 %val, i32 0 | ||
| ret <4 x i32> %ret | ||
| } | ||
|
|
||
| define <2 x i64> @scalar_to_2xi64(i64 %val) { | ||
| ; CHECK-LABEL: scalar_to_2xi64: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: vinsgr2vr.d $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <2 x i64> poison, i64 %val, i32 0 | ||
| ret <2 x i64> %ret | ||
| } | ||
|
|
||
| define <4 x float> @scalar_to_4xf32(float %val) { | ||
|
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. Seems these could be
Member
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.
|
||
| ; CHECK-LABEL: scalar_to_4xf32: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: movfr2gr.s $a0, $fa0 | ||
| ; CHECK-NEXT: vinsgr2vr.w $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <4 x float> poison, float %val, i32 0 | ||
| ret <4 x float> %ret | ||
| } | ||
|
|
||
| define <2 x double> @scalar_to_2xf64(double %val) { | ||
| ; CHECK-LABEL: scalar_to_2xf64: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: movfr2gr.d $a0, $fa0 | ||
| ; CHECK-NEXT: vinsgr2vr.d $vr0, $a0, 0 | ||
| ; CHECK-NEXT: ret | ||
| %ret = insertelement <2 x double> poison, double %val, i32 0 | ||
| ret <2 x double> %ret | ||
| } | ||
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.
Why not make it
Legaland define patterns in .td files.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.
Hi @SixWeining, I thought that in
.tdfiles, we can only lower operations to machine instructions. However, if this is done during ISel lowering, it gets canonicalized into a different standard SDNode. Could there be potential benefits if we incorporate some DAGCombine patterns in this approach?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 cannot replace
scalar_to_vectorwith theVINSGR2VRinstruction because of the unknown?.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, I agree.
For the test case in the commit message, we do too many transforms: insert_vector_elt -> BUILD_VECTOR -> scalar_to_vector -> insert_vector_elt. Could we do: insert_vector_elt -> BUILD_VECTOR -> insert_vector_elt ?
Maybe we should change:
LoongArchTargetLowering::lowerBUILD_VECTOR()orSelectionDAGLegalize::ExpandBUILD_VECTOR().