Skip to content

Commit

Permalink
JIT: fix permute node type in AVX simd sum
Browse files Browse the repository at this point in the history
In `gtNewSimdSumNode` we need to type permute nodes as `simd16`, not the sum's type.
If we split the tree at the permute we spill to the wrong typed temp.

Also provide the ability to halt stress tree splitting after some number of splits.

Fixes dotnet#102335.
  • Loading branch information
AndyAyersMS committed Jun 19, 2024
1 parent 01b0a30 commit 65b4ffd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5701,12 +5701,20 @@ void Compiler::SplitTreesRandomly()
rng.Init(info.compMethodHash() ^ 0x077cc4d4);

// Splitting creates a lot of new locals. Set a limit on how many we end up creating here.
unsigned maxLvaCount = max(lvaCount * 2, 50000u);
unsigned maxLvaCount = max(lvaCount * 2, 50000u);
int numSplit = 0;
const int splitLimit = JitConfig.JitStressSplitTreeLimit();

for (BasicBlock* block : Blocks())
{
for (Statement* stmt : block->NonPhiStatements())
{
if ((splitLimit >= 0) && (numSplit >= splitLimit))
{
JITDUMP("Reached split limit (%d) -- stopping\n", splitLimit);
return;
}

int numTrees = 0;
for (GenTree* tree : stmt->TreeList())
{
Expand Down Expand Up @@ -5739,6 +5747,7 @@ void Compiler::SplitTreesRandomly()

fgMorphStmtBlockOps(block, stmt);
gtUpdateStmtSideEffects(stmt);
numSplit++;
}

break;
Expand All @@ -5754,6 +5763,9 @@ void Compiler::SplitTreesRandomly()
}
}
}

JITDUMP("Split %d trees\n", numSplit);

#endif
}

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26307,13 +26307,13 @@ GenTree* Compiler::gtNewSimdSumNode(var_types type, GenTree* op1, CorInfoType si
{
assert(compIsaSupportedDebugOnly(InstructionSet_AVX));
// The permute below gives us [0, 1, 2, 3] -> [1, 0, 3, 2]
op1 = gtNewSimdHWIntrinsicNode(type, op1, gtNewIconNode((int)0b10110001, TYP_INT), NI_AVX_Permute,
op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, gtNewIconNode((int)0b10110001, TYP_INT), NI_AVX_Permute,
simdBaseJitType, simdSize);
// The add below now results in [0 + 1, 1 + 0, 2 + 3, 3 + 2]
op1 = gtNewSimdBinOpNode(GT_ADD, TYP_SIMD16, op1, op1Shuffled, simdBaseJitType, simdSize);
op1Shuffled = fgMakeMultiUse(&op1);
// The permute below gives us [0 + 1, 1 + 0, 2 + 3, 3 + 2] -> [2 + 3, 3 + 2, 0 + 1, 1 + 0]
op1 = gtNewSimdHWIntrinsicNode(type, op1, gtNewIconNode((int)0b01001110, TYP_INT), NI_AVX_Permute,
op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, gtNewIconNode((int)0b01001110, TYP_INT), NI_AVX_Permute,
simdBaseJitType, simdSize);
}
else
Expand Down Expand Up @@ -26345,7 +26345,7 @@ GenTree* Compiler::gtNewSimdSumNode(var_types type, GenTree* op1, CorInfoType si
{
assert(compIsaSupportedDebugOnly(InstructionSet_AVX));
// The permute below gives us [0, 1] -> [1, 0]
op1 = gtNewSimdHWIntrinsicNode(type, op1, gtNewIconNode((int)0b0001, TYP_INT), NI_AVX_Permute,
op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, gtNewIconNode((int)0b0001, TYP_INT), NI_AVX_Permute,
simdBaseJitType, simdSize);
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ CONFIG_INTEGER(JitStressProcedureSplitting, W("JitStressProcedureSplitting"), 0)
CONFIG_INTEGER(JitStressRegs, W("JitStressRegs"), 0)
CONFIG_STRING(JitStressRegsRange, W("JitStressRegsRange")) // Only apply JitStressRegs to methods in this hash range

// If non-negative value N, only stress split the first N trees.
CONFIG_INTEGER(JitStressSplitTreeLimit, W("JitStressSplitTreeLimit"), -1)

// If non-zero, assert if # of VNF_MapSelect applications considered reaches this.
CONFIG_INTEGER(JitVNMapSelLimit, W("JitVNMapSelLimit"), 0)

Expand Down

0 comments on commit 65b4ffd

Please sign in to comment.