Skip to content

Commit aa4ac3f

Browse files
Ensure that the CvtVectorToMask node is inserted in the right place (#103356)
1 parent e58d907 commit aa4ac3f

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/coreclr/jit/rationalize.cpp

+29-15
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,
157157
// Replace "tree" with "call"
158158
if (parents.Height() > 1)
159159
{
160-
GenTree* tmpInsertionPoint = insertionPoint;
161-
162160
if (tmpNum != BAD_VAR_NUM)
163161
{
164162
result = comp->gtNewLclvNode(tmpNum, retType);
@@ -169,18 +167,17 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,
169167
#if defined(FEATURE_HW_INTRINSICS)
170168
// No managed call returns TYP_MASK, so convert it from a TYP_SIMD
171169

172-
var_types simdType = tree->TypeGet();
173-
assert(varTypeIsSIMD(simdType));
174-
175170
unsigned simdSize;
176171
CorInfoType simdBaseJitType = comp->getBaseJitTypeAndSizeOfSIMDType(call->gtRetClsHnd, &simdSize);
177172
assert(simdSize != 0);
178173

179-
GenTree* cvtNode = comp->gtNewSimdCvtVectorToMaskNode(TYP_MASK, result, simdBaseJitType, simdSize);
180-
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(cvtNode), cvtNode));
181-
result = cvtNode;
174+
result = comp->gtNewSimdCvtVectorToMaskNode(TYP_MASK, result, simdBaseJitType, simdSize);
182175

183-
tmpInsertionPoint = result;
176+
if (tmpNum == BAD_VAR_NUM)
177+
{
178+
// Propagate flags of "call" to its parent.
179+
result->gtFlags |= (call->gtFlags & GTF_ALL_EFFECT) | GTF_CALL;
180+
}
184181
#else
185182
unreached();
186183
#endif // FEATURE_HW_INTRINSICS
@@ -190,27 +187,44 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,
190187

191188
if (tmpNum != BAD_VAR_NUM)
192189
{
190+
// We have a return buffer, so we need to insert both the result and the call
191+
// since they are independent trees. If we have a convert node, it will indirectly
192+
// insert the local node.
193+
194+
comp->gtSetEvalOrder(result);
195+
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(result), result));
196+
197+
comp->gtSetEvalOrder(call);
198+
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(call), call));
199+
}
200+
else
201+
{
202+
// We don't have a return buffer, so we only need to insert the result, which
203+
// will indirectly insert the call in the case we have a convert node as well.
204+
193205
comp->gtSetEvalOrder(result);
194-
BlockRange().InsertAfter(tmpInsertionPoint, LIR::Range(comp->fgSetTreeSeq(result), result));
206+
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(result), result));
195207
}
196208
}
197209
else
198210
{
199211
// If there's no parent, the tree being replaced is the root of the
200212
// statement (and no special handling is necessary).
201213
*use = result;
202-
}
203214

204-
comp->gtSetEvalOrder(call);
205-
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(call), call));
215+
comp->gtSetEvalOrder(call);
216+
BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(call), call));
217+
}
206218

207-
if (result == call)
219+
if (tmpNum == BAD_VAR_NUM)
208220
{
209221
// Propagate flags of "call" to its parents.
222+
GenTreeFlags callFlags = (call->gtFlags & GTF_ALL_EFFECT) | GTF_CALL;
223+
210224
// 0 is current node, so start at 1
211225
for (int i = 1; i < parents.Height(); i++)
212226
{
213-
parents.Top(i)->gtFlags |= (call->gtFlags & GTF_ALL_EFFECT) | GTF_CALL;
227+
parents.Top(i)->gtFlags |= callFlags;
214228
}
215229
}
216230
else

0 commit comments

Comments
 (0)