[llvm] [LoongArch] Custom legalizing build_vector with same constant elements (PR #150584)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 26 01:24:10 PDT 2025


================
@@ -613,9 +595,10 @@ define void @buildvector_v2f64_with_constant(ptr %dst, double %a0) nounwind {
 ; CHECK-LABEL: buildvector_v2f64_with_constant:
 ; CHECK:       # %bb.0: # %entry
 ; CHECK-NEXT:    # kill: def $f0_64 killed $f0_64 def $vr0
-; CHECK-NEXT:    vldi $vr1, -1024
-; CHECK-NEXT:    vpackev.d $vr0, $vr1, $vr0
-; CHECK-NEXT:    vst $vr0, $a0, 0
+; CHECK-NEXT:    lu52i.d $a1, $zero, 1024
+; CHECK-NEXT:    vreplgr2vr.d $vr1, $a1
+; CHECK-NEXT:    vextrins.d $vr1, $vr0, 0
+; CHECK-NEXT:    vst $vr1, $a0, 0
----------------
zhaoqi5 wrote:

When Legalizing `BUILD_VECTOR` whose elememts are all same floating point constant, we will firstly convert it to integer type. And then use `vrepli` or `a Instruction sequence (if the constant is too large)` to generate the constant.

For example:
```
BUILD_VECTOR ConstantFP:f64<2.000000e+00>, ConstantFP:f64<2.000000e+00>
==>
BUILD_VECTOR Constant:i64<4611686018427387904>, Constant:i64<4611686018427387904>
```
The converted constant is large, so a `lu52i.d` is produced to generate this constant. And then, broadcast it, and insert the elements we want to the vector.

https://github.com/llvm/llvm-project/pull/150584


More information about the llvm-commits mailing list