release/23.x: [Mips] Legalize vector UNDEF instead of expanding to zero BUILD_VECTOR (#211503) - #217519
Merged
Merged
Conversation
Member
Author
|
@arsenm What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-backend-mips Author: llvmbot ChangesBackport b1c24ea Requested by: @brad0 Full diff: https://github.com/llvm/llvm-project/pull/217519.diff 2 Files Affected:
diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
index d5941fc8e0b33..628e8d4359f7c 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
@@ -447,6 +447,7 @@ addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) {
setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Legal);
setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal);
setOperationAction(ISD::BUILD_VECTOR, Ty, Custom);
+ setOperationAction(ISD::UNDEF, Ty, Legal);
if (Ty != MVT::v8f16) {
setOperationAction(ISD::FABS, Ty, Legal);
diff --git a/llvm/test/CodeGen/Mips/msa/buildvector-undef-loop.ll b/llvm/test/CodeGen/Mips/msa/buildvector-undef-loop.ll
new file mode 100644
index 0000000000000..80fa4049d0f10
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/msa/buildvector-undef-loop.ll
@@ -0,0 +1,37 @@
+; RUN: llc -mtriple=mips64el-linux-gnu64abi -mcpu=mips64r5 -mattr=+msa < %s \
+; RUN: | FileCheck %s --check-prefixes=MIPS64R5
+
+@v4f32 = global <4 x float> <float 0.0, float 0.0, float 0.0, float 0.0>
+
+define void @nonsplatvalue_v4f32(float %a, float %b, float %c, float %d) nounwind {
+; MIPS64R5-LABEL: nonsplatvalue_v4f32:
+; MIPS64R5: # %bb.0:
+; MIPS64R5-NEXT: # kill: def $f15 killed $f15 def $w15
+; MIPS64R5-NEXT: # kill: def $f14 killed $f14 def $w14
+; MIPS64R5-NEXT: # kill: def $f13 killed $f13 def $w13
+; MIPS64R5-NEXT: # kill: def $f12 killed $f12 def $w12
+; MIPS64R5-NEXT: insve.w $w0[0], $w12[0]
+; MIPS64R5-NEXT: insve.w $w0[1], $w13[0]
+; MIPS64R5-NEXT: insve.w $w0[2], $w14[0]
+; MIPS64R5-NEXT: insve.w $w0[3], $w15[0]
+; MIPS64R5-NEXT: fmax_a.w $w0, $w0, $w0
+; MIPS64R5-NEXT: lui $1, %highest(v4f32)
+; MIPS64R5-NEXT: daddiu $1, $1, %higher(v4f32)
+; MIPS64R5-NEXT: dsll $1, $1, 16
+; MIPS64R5-NEXT: daddiu $1, $1, %hi(v4f32)
+; MIPS64R5-NEXT: dsll $1, $1, 16
+; MIPS64R5-NEXT: daddiu $1, $1, %lo(v4f32)
+; MIPS64R5-NEXT: jr $ra
+; MIPS64R5-NEXT: st.w $w0, 0($1)
+ %v0 = insertelement <4 x float> poison, float %a, i64 0
+ %v1 = insertelement <4 x float> %v0, float %b, i32 1
+ %v2 = insertelement <4 x float> %v1, float %c, i32 2
+ %v3 = insertelement <4 x float> %v2, float %d, i32 3
+
+ %fabs = call <4 x float> @llvm.fabs.v4f32(<4 x float> %v3)
+ store volatile <4 x float> %fabs, ptr @v4f32
+
+ ret void
+}
+
+declare <4 x float> @llvm.fabs.v4f32(<4 x float>)
|
|
|
alexrp
approved these changes
Aug 23, 2026
llvm#211503) Currently, MIPS MSA expands ISD::UNDEF into a BUILD_VECTOR of all zeros during legalization. This creates an infinite loop in DAGCombiner when the following occurs: 1.Mips lower BUILD_VECTOR expands non-splat vectors into INSERT_VECTOR_ELT with creating undef node 2.Then legalization expands UNDEF back to BUILD_VECTOR zero 3.Mips lower BUILD_VECTOR converts zero vector to BITCAST 4.DAGCombiner optimizes BITCAST(zero) to UNDEF 5.Back to step 2, infinite loop Fix llvm#210229. (cherry picked from commit b1c24ea)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport b1c24ea
Requested by: @brad0