This fixes issue 62242
This code block can potentially swap the order of V1 and V2 in Ops and therefore
also in the unpck instruction generated.
SDValue &Op = Ops[Elt & 1];
if (M < NumElts && (Op.isUndef() || Op == V1))
Op = V1;
else if (NumElts <= M && (Op.isUndef() || Op == V2)) {
Op = V2;
NormM -= NumElts;
} else
return SDValue();But the permute mask is calculated assuming the first operand being V1 and
second V2, therefore causing a mis-compile.
First check if the input operands are swapped, and then calculate the permute
mask based on that.
Is the OpsSwapped logic necessary?
for (int Elt = 0; Elt != NumElts; ++Elt) { int M = Mask[Elt]; if (M < 0) continue; int NormM = M; if (NumElts <= M) NormM -= NumElts; bool IsFirstOp = M < NumElts; int BaseMaskElt = NumLaneElts * (NormM / NumLaneElts) + (2 * (NormM % NumHalfLaneElts)); if ((IsFirstOp && V1 == Ops[0]) || (!IsFirstOp && V2 == Ops[0])) PermuteMask[Elt] = BaseMaskElt; else if if ((IsFirstOp && V1 == Ops[1]) || (!IsFirstOp && V2 == Ops[1])) PermuteMask[Elt] = BaseMaskElt + 1; }I think there probably needs to be an assertion there as well someplace.