Skip to content

Commit 87a35d6

Browse files
authored
JIT: Advance cursors through stores in strength reduction (dotnet#105267)
This allows us to look through CSE'd locals when an IV was CSE'd. Example diff: ```csharp private static void CopyInts(int[] arr1, int[] arr2) { if (arr2.Length != arr1.Length) return; for (int i = 0; i < arr1.Length; i++) { arr2[i] = arr1[i]; } } ``` ```diff @@ -1,14 +1,16 @@ G_M55903_IG03: ;; offset=0x000C - xor eax, eax test r8d, r8d - jle SHORT G_M55903_IG05 - ;; size=7 bbWeight=0.50 PerfScore 0.75 + jle SHORT G_M55903_IG06 + ;; size=5 bbWeight=0.50 PerfScore 0.62 -G_M55903_IG04: ;; offset=0x0013 - mov r10d, eax - mov r9d, dword ptr [rcx+4*r10+0x10] - mov dword ptr [rdx+4*r10+0x10], r9d - inc eax - cmp r8d, eax - jg SHORT G_M55903_IG04 - ;; size=20 bbWeight=3.96 PerfScore 18.81 +G_M55903_IG04: ;; offset=0x0011 + mov eax, 16 + ;; size=5 bbWeight=0.25 PerfScore 0.06 + +G_M55903_IG05: ;; offset=0x0016 + mov r10d, dword ptr [rcx+rax] + mov dword ptr [rdx+rax], r10d + add rax, 4 + dec r8d + jne SHORT G_M55903_IG05 + ;; size=17 bbWeight=3.96 PerfScore 17.82 ``` arm64 especially benefits from strength reduction, e.g. a benchmark for the above: ``` BenchmarkDotNet v0.13.12, Ubuntu 22.04.4 LTS (Jammy Jellyfish) Unknown processor Job-GXMAGJ : .NET 9.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD Job-MLUOLU : .NET 9.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD ``` | Method | Toolchain | Mean | Error | Ratio | |--------- |------------------------ |---------:|----------:|------:| | CopyInts | Main | 6.683 μs | 0.0010 μs | 1.00 | | CopyInts | PR | 5.014 μs | 0.0003 μs | 0.75 |
1 parent 8ef27e2 commit 87a35d6

File tree

2 files changed

+211
-51
lines changed

2 files changed

+211
-51
lines changed

src/coreclr/jit/compiler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7698,7 +7698,7 @@ class Compiler
76987698
BasicBlock* exiting,
76997699
LoopLocalOccurrences* loopLocals);
77007700
bool optCanAndShouldChangeExitTest(GenTree* cond, bool dump);
7701-
bool optPrimaryIVHasNonLoopUses(unsigned lclNum, FlowGraphNaturalLoop* loop, LoopLocalOccurrences* loopLocals);
7701+
bool optLocalHasNonLoopUses(unsigned lclNum, FlowGraphNaturalLoop* loop, LoopLocalOccurrences* loopLocals);
77027702

77037703
bool optWidenIVs(ScalarEvolutionContext& scevContext, FlowGraphNaturalLoop* loop, LoopLocalOccurrences* loopLocals);
77047704
bool optWidenPrimaryIV(FlowGraphNaturalLoop* loop,

0 commit comments

Comments
 (0)