Skip to content

Commit

Permalink
Fix a bug in lowerxarch related to merging Sse41.Insert chains
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jan 3, 2023
1 parent b85156c commit 51bb6c3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,9 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)

if (comp->compOpportunisticallyDependsOn(InstructionSet_SSE41))
{
assert(argCnt <= 4);
GenTree* insertedNodes[4];

for (N = 1; N < argCnt - 1; N++)
{
// We will be constructing the following parts:
Expand Down Expand Up @@ -2837,10 +2840,12 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
idx = comp->gtNewIconNode(N << 4, TYP_INT);
BlockRange().InsertAfter(tmp2, idx);

tmp1 = comp->gtNewSimdHWIntrinsicNode(simdType, tmp1, tmp2, idx, NI_SSE41_Insert, simdBaseJitType,
tmp3 = comp->gtNewSimdHWIntrinsicNode(simdType, tmp1, tmp2, idx, NI_SSE41_Insert, simdBaseJitType,
simdSize);
BlockRange().InsertAfter(idx, tmp1);
LowerNode(tmp1);
BlockRange().InsertAfter(idx, tmp3);

insertedNodes[N] = tmp3;
tmp1 = tmp3;
}

// We will be constructing the following parts:
Expand Down Expand Up @@ -2868,6 +2873,18 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
BlockRange().InsertAfter(tmp2, idx);

node->ResetHWIntrinsicId(NI_SSE41_Insert, comp, tmp1, tmp2, idx);

for (N = 1; N < argCnt - 1; N++)
{
// LowerNode for NI_SSE41_Insert specially handles zeros, constants, and certain mask values
// to do the minimal number of operations and may merge together two neighboring inserts that
// don't have any side effects between them. Because of this and because of the interdependence
// of the inserts we've created above, we need to wait to lower the generated inserts until after
// we've completed the chain.

GenTree* insertedNode = insertedNodes[N];
LowerNode(insertedNode);
}
break;
}

Expand Down

0 comments on commit 51bb6c3

Please sign in to comment.