[llvm] [MIPS] fix assert on `undef` first mask element (PR #203390)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 03:01:11 PDT 2026
================
@@ -3132,27 +3132,31 @@ static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy,
SDLoc DL(Op);
int ResTyNumElts = ResTy.getVectorNumElements();
- assert(Indices[0] >= 0 &&
- "shuffle mask starts with an UNDEF, which is not expected");
-
for (int i = 0; i < ResTyNumElts; ++i) {
- // Idx == -1 means UNDEF
+ // Idx == -1 means UNDEF/poison
int Idx = Indices[i];
if (0 <= Idx && Idx < ResTyNumElts)
Using1stVec = true;
if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2)
Using2ndVec = true;
}
+
+ // Find the first non-undef index use as a default when there is a leading
+ // UNDEF/poison.
int LastValidIndex = 0;
- for (size_t i = 0; i < Indices.size(); i++) {
- int Idx = Indices[i];
- if (Idx < 0) {
- // Continue using splati index or use the last valid index.
- Idx = isSPLATI ? Indices[0] : LastValidIndex;
- } else {
+ for (int Idx : Indices)
+ if (Idx >= 0) {
LastValidIndex = Idx;
+ break;
}
+
+ for (int Idx : Indices) {
+ if (Idx < 0)
+ Idx = LastValidIndex;
----------------
yingopq wrote:
Did we need to check the code `Indices[0]`?
Is it possible to only enter your newly added code when it is invalid?
https://github.com/llvm/llvm-project/pull/203390
More information about the llvm-commits
mailing list