You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT: Strength reduction no longer kicks in in .NET10 #121533
Previously, the input[i] was strength reduced to advance by 4 and the loop was made downwards counted; that's no longer the case, leading to worse code gen.
publicstaticunsafevoidRadixSort(Span<int>input,Span<int>output,Vector128<float>[]mins,Vector128<float>[]maxs,intaxis){constintradixSize=11;constintbinSize=1<<radixSize;constintmask=binSize-1;constintpasses=3;int*prefixSum=stackallocint[binSize*passes];// Compute histogram for all passesfor(inti=0;i<input.Length;i++){uintkey=GetKey(input[i]);GetPrefixSumRef(key,0)++;GetPrefixSumRef(key,1)++;GetPrefixSumRef(key,2)++;}refintGetPrefixSumRef(uintkey,intpass){uintradix=(key>>(pass*radixSize))&mask;refintoffset=refprefixSum[radix+pass*binSize];returnrefoffset;}[MethodImpl(MethodImplOptions.AggressiveInlining)]uintGetKey(intel){returnFloatToKey(mins[el][axis]+maxs[el][axis]);}}
Looks like a side effect of 41be5e2. We don't invert the loop anymore and strength reduction is not able to prove safety on the loop in its non-inverted state.
So the actual issue is that the loop inversion heuristic doesn't consider this profitable. I see it now:
Analyzing iteration for L00 with header BB03
Preheader = BB01
Checking exiting block BB03
Could not extract an IV
Could not find any IV
Condition in block BB03 of loop L00 is a candidate for duplication to invert the loop
L00 exceeds inversion size limit of 100
L00 might benefit from cloning, but is too large to invert.
Looking at the PR, do I understand correctly that this number was tuned to be 100 mostly to prevent too much loop-cloning (and the associated size increase)? If yes: Doesn't loop-cloning, among other loop opts, have it's own heuristic do decide if its profitable. Why adjust loop-inversion heuristic to control the amount of cloning, when instead the loop-cloning heuristic itself could be changed?
I think loop-inversion itself brings a relativly small size increase, unless for already very small loops, and it enables other opts. So it seems like that should be done more aggresivly? Please let me know where I said something wrong.
Activity
jakobbotsch commentedon Nov 11, 2025
Looks like a side effect of 41be5e2. We don't invert the loop anymore and strength reduction is not able to prove safety on the loop in its non-inverted state.
BoyBaykiller commentedon Nov 12, 2025
So the actual issue is that the loop inversion heuristic doesn't consider this profitable. I see it now:
Looking at the PR, do I understand correctly that this number was tuned to be 100 mostly to prevent too much loop-cloning (and the associated size increase)? If yes: Doesn't loop-cloning, among other loop opts, have it's own heuristic do decide if its profitable. Why adjust loop-inversion heuristic to control the amount of cloning, when instead the loop-cloning heuristic itself could be changed?
I think loop-inversion itself brings a relativly small size increase, unless for already very small loops, and it enables other opts. So it seems like that should be done more aggresivly? Please let me know where I said something wrong.
JulieLeeMSFT commentedon Dec 11, 2025
cc @jakobbotsch to respond to the question.
AndyAyersMS commentedon Jun 23, 2026
Fixed by #129722