@@ -4119,61 +4119,61 @@ void SelectionDAGBuilder::visitShuffleVector(const User &I) {
4119
4119
return;
4120
4120
}
4121
4121
4122
- if (SrcNumElts > MaskNumElts) {
4123
- // Analyze the access pattern of the vector to see if we can extract
4124
- // two subvectors and do the shuffle.
4125
- int StartIdx[2] = { -1, -1 }; // StartIdx to extract from
4126
- bool CanExtract = true;
4127
- for (int Idx : Mask) {
4128
- unsigned Input = 0;
4129
- if (Idx < 0)
4130
- continue;
4122
+ assert(SrcNumElts > MaskNumElts);
4131
4123
4132
- if (Idx >= (int)SrcNumElts) {
4133
- Input = 1;
4134
- Idx -= SrcNumElts;
4135
- }
4124
+ // Analyze the access pattern of the vector to see if we can extract
4125
+ // two subvectors and do the shuffle.
4126
+ int StartIdx[2] = {-1, -1}; // StartIdx to extract from
4127
+ bool CanExtract = true;
4128
+ for (int Idx : Mask) {
4129
+ unsigned Input = 0;
4130
+ if (Idx < 0)
4131
+ continue;
4136
4132
4137
- // If all the indices come from the same MaskNumElts sized portion of
4138
- // the sources we can use extract. Also make sure the extract wouldn't
4139
- // extract past the end of the source.
4140
- int NewStartIdx = alignDown(Idx, MaskNumElts);
4141
- if (NewStartIdx + MaskNumElts > SrcNumElts ||
4142
- (StartIdx[Input] >= 0 && StartIdx[Input] != NewStartIdx))
4143
- CanExtract = false;
4144
- // Make sure we always update StartIdx as we use it to track if all
4145
- // elements are undef.
4146
- StartIdx[Input] = NewStartIdx;
4133
+ if (Idx >= (int)SrcNumElts) {
4134
+ Input = 1;
4135
+ Idx -= SrcNumElts;
4147
4136
}
4148
4137
4149
- if (StartIdx[0] < 0 && StartIdx[1] < 0) {
4150
- setValue(&I, DAG.getUNDEF(VT)); // Vectors are not used.
4151
- return;
4152
- }
4153
- if (CanExtract) {
4154
- // Extract appropriate subvector and generate a vector shuffle
4155
- for (unsigned Input = 0; Input < 2; ++Input) {
4156
- SDValue &Src = Input == 0 ? Src1 : Src2;
4157
- if (StartIdx[Input] < 0)
4158
- Src = DAG.getUNDEF(VT);
4159
- else {
4160
- Src = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src,
4161
- DAG.getVectorIdxConstant(StartIdx[Input], DL));
4162
- }
4163
- }
4138
+ // If all the indices come from the same MaskNumElts sized portion of
4139
+ // the sources we can use extract. Also make sure the extract wouldn't
4140
+ // extract past the end of the source.
4141
+ int NewStartIdx = alignDown(Idx, MaskNumElts);
4142
+ if (NewStartIdx + MaskNumElts > SrcNumElts ||
4143
+ (StartIdx[Input] >= 0 && StartIdx[Input] != NewStartIdx))
4144
+ CanExtract = false;
4145
+ // Make sure we always update StartIdx as we use it to track if all
4146
+ // elements are undef.
4147
+ StartIdx[Input] = NewStartIdx;
4148
+ }
4164
4149
4165
- // Calculate new mask.
4166
- SmallVector<int, 8> MappedOps(Mask);
4167
- for (int &Idx : MappedOps) {
4168
- if (Idx >= (int)SrcNumElts)
4169
- Idx -= SrcNumElts + StartIdx[1] - MaskNumElts;
4170
- else if (Idx >= 0)
4171
- Idx -= StartIdx[0];
4150
+ if (StartIdx[0] < 0 && StartIdx[1] < 0) {
4151
+ setValue(&I, DAG.getUNDEF(VT)); // Vectors are not used.
4152
+ return;
4153
+ }
4154
+ if (CanExtract) {
4155
+ // Extract appropriate subvector and generate a vector shuffle
4156
+ for (unsigned Input = 0; Input < 2; ++Input) {
4157
+ SDValue &Src = Input == 0 ? Src1 : Src2;
4158
+ if (StartIdx[Input] < 0)
4159
+ Src = DAG.getUNDEF(VT);
4160
+ else {
4161
+ Src = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src,
4162
+ DAG.getVectorIdxConstant(StartIdx[Input], DL));
4172
4163
}
4164
+ }
4173
4165
4174
- setValue(&I, DAG.getVectorShuffle(VT, DL, Src1, Src2, MappedOps));
4175
- return;
4166
+ // Calculate new mask.
4167
+ SmallVector<int, 8> MappedOps(Mask);
4168
+ for (int &Idx : MappedOps) {
4169
+ if (Idx >= (int)SrcNumElts)
4170
+ Idx -= SrcNumElts + StartIdx[1] - MaskNumElts;
4171
+ else if (Idx >= 0)
4172
+ Idx -= StartIdx[0];
4176
4173
}
4174
+
4175
+ setValue(&I, DAG.getVectorShuffle(VT, DL, Src1, Src2, MappedOps));
4176
+ return;
4177
4177
}
4178
4178
4179
4179
// We can't use either concat vectors or extract subvectors so fall back to
0 commit comments