diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -14972,24 +14972,36 @@ // Example (even elements from first vector): // vector_shuffle<0,16,1,17,2,18,3,19,4,20,5,21,6,22,7,23> t1, if (Mask[0] < NumElts) - for (int i = 1, e = Mask.size(); i < e; i += 2) + for (int i = 1, e = Mask.size(); i < e; i += 2) { + if (ShuffV[i] < 0) + continue; ShuffV[i] = (ShuffV[i - 1] + NumElts); + } // Example (odd elements from first vector): // vector_shuffle<16,0,17,1,18,2,19,3,20,4,21,5,22,6,23,7> t1, else - for (int i = 0, e = Mask.size(); i < e; i += 2) + for (int i = 0, e = Mask.size(); i < e; i += 2) { + if (ShuffV[i] < 0) + continue; ShuffV[i] = (ShuffV[i + 1] + NumElts); + } } else { // Example (even elements from first vector): // vector_shuffle<0,16,1,17,2,18,3,19,4,20,5,21,6,22,7,23> , t1 if (Mask[0] < NumElts) - for (int i = 0, e = Mask.size(); i < e; i += 2) + for (int i = 0, e = Mask.size(); i < e; i += 2) { + if (ShuffV[i] < 0) + continue; ShuffV[i] = ShuffV[i + 1] - NumElts; + } // Example (odd elements from first vector): // vector_shuffle<16,0,17,1,18,2,19,3,20,4,21,5,22,6,23,7> , t1 else - for (int i = 1, e = Mask.size(); i < e; i += 2) + for (int i = 1, e = Mask.size(); i < e; i += 2) { + if (ShuffV[i] < 0) + continue; ShuffV[i] = ShuffV[i - 1] - NumElts; + } } // If the RHS has undefs, we need to remove them since we may have created