-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: Unify preheader/exit weight calculation logic #98407
Conversation
The preheader/exit weight calculation is essentially the same logic, so unify to use the logic from the exit weight calculation. This also fixes a bug in the preheader weight calculation introduced by my recent change where we sometimes mistakenly used the weight of the newly inserted preheader instead of the header block to compute a likelihood.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsThe preheader/exit weight calculation is essentially the same logic, so unify it to use the exit weight. This also fixes a bug in the preheader weight calculation introduced by my recent change where we sometimes mistakenly used the weight of the newly inserted preheader instead of the header block to compute a likelihood. The bug was here: runtime/src/coreclr/jit/optimizer.cpp Lines 3075 to 3087 in d464313
The Fix #98370
|
cc @dotnet/jit-contrib PTAL @AndyAyersMS |
Diff results for #98407Assembly diffsAssembly diffs for linux/arm64 ran on windows/x64Diffs are based on 2,528,537 contexts (1,004,581 MinOpts, 1,523,956 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 14 (0.00%) Overall (-29,788 bytes)
FullOpts (-29,788 bytes)
Assembly diffs for linux/x64 ran on windows/x64Diffs are based on 2,531,978 contexts (984,938 MinOpts, 1,547,040 FullOpts). MISSED contexts: 1 (0.00%) Overall (-39,315 bytes)
FullOpts (-39,315 bytes)
Assembly diffs for osx/arm64 ran on windows/x64Diffs are based on 2,298,749 contexts (931,667 MinOpts, 1,367,082 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 4 (0.00%) Overall (-14,884 bytes)
FullOpts (-14,884 bytes)
Assembly diffs for windows/arm64 ran on windows/x64Diffs are based on 2,380,843 contexts (948,167 MinOpts, 1,432,676 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 9 (0.00%) Overall (+1,588 bytes)
FullOpts (+1,588 bytes)
Assembly diffs for windows/x64 ran on windows/x64Diffs are based on 2,821,026 contexts (1,163,479 MinOpts, 1,657,547 FullOpts). Overall (+30,637 bytes)
FullOpts (+30,637 bytes)
Details here Assembly diffs for linux/arm ran on windows/x86Diffs are based on 2,242,904 contexts (830,244 MinOpts, 1,412,660 FullOpts). MISSED contexts: 73,620 (3.18%) Overall (-3,540 bytes)
FullOpts (-3,540 bytes)
Assembly diffs for windows/x86 ran on windows/x86Diffs are based on 2,599,256 contexts (1,005,474 MinOpts, 1,593,782 FullOpts). MISSED contexts: base: 625 (0.02%), diff: 667 (0.03%) Overall (-5,415 bytes)
FullOpts (-5,415 bytes)
Details here Throughput diffsThroughput diffs for linux/arm64 ran on windows/x64Overall (-0.01% to +0.01%)
MinOpts (-0.00% to +0.01%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on windows/x64Overall (-0.01% to +0.01%)
FullOpts (-0.02% to +0.01%)
Throughput diffs for osx/arm64 ran on windows/x64Overall (-0.01% to +0.00%)
FullOpts (-0.02% to +0.00%)
Throughput diffs for windows/arm64 ran on windows/x64Overall (-0.00% to +0.03%)
MinOpts (-0.00% to +0.01%)
FullOpts (-0.00% to +0.04%)
Throughput diffs for windows/x64 ran on windows/x64FullOpts (-0.00% to +0.01%)
Details here Throughput diffs for linux/arm64 ran on linux/x64Overall (-0.01% to +0.01%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on linux/x64Overall (-0.01% to +0.00%)
FullOpts (-0.02% to +0.01%)
Details here Throughput diffs for windows/x86 ran on windows/x86Overall (-0.01% to +0.00%)
FullOpts (-0.01% to +0.00%)
Details here |
Diff results for #98407Assembly diffsAssembly diffs for linux/arm64 ran on linux/x64Diffs are based on 2,528,537 contexts (1,004,581 MinOpts, 1,523,956 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 14 (0.00%) Overall (-29,788 bytes)
FullOpts (-29,788 bytes)
Assembly diffs for linux/x64 ran on linux/x64Diffs are based on 2,531,978 contexts (984,938 MinOpts, 1,547,040 FullOpts). MISSED contexts: 1 (0.00%) Overall (-39,315 bytes)
FullOpts (-39,315 bytes)
Assembly diffs for osx/arm64 ran on linux/x64Diffs are based on 2,298,749 contexts (931,667 MinOpts, 1,367,082 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 4 (0.00%) Overall (-14,884 bytes)
FullOpts (-14,884 bytes)
Assembly diffs for windows/arm64 ran on linux/x64Diffs are based on 2,380,843 contexts (948,167 MinOpts, 1,432,676 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 9 (0.00%) Overall (+1,588 bytes)
FullOpts (+1,588 bytes)
Assembly diffs for windows/x64 ran on linux/x64Diffs are based on 2,821,026 contexts (1,163,479 MinOpts, 1,657,547 FullOpts). Overall (+30,637 bytes)
FullOpts (+30,637 bytes)
Details here Throughput diffsThroughput diffs for linux/arm64 ran on windows/x64Overall (-0.01% to +0.01%)
MinOpts (-0.01% to +0.00%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on windows/x64Overall (-0.01% to +0.01%)
FullOpts (-0.02% to +0.01%)
Throughput diffs for osx/arm64 ran on windows/x64Overall (-0.01% to +0.00%)
MinOpts (-0.00% to +0.01%)
FullOpts (-0.02% to +0.00%)
Throughput diffs for windows/arm64 ran on windows/x64Overall (-0.00% to +0.03%)
MinOpts (-0.01% to +0.00%)
FullOpts (-0.00% to +0.04%)
Throughput diffs for windows/x64 ran on windows/x64FullOpts (-0.00% to +0.01%)
Details here Throughput diffs for windows/x86 ran on linux/x86Overall (-0.01% to +0.00%)
FullOpts (-0.01% to +0.00%)
Details here Throughput diffs for linux/arm64 ran on linux/x64Overall (-0.01% to +0.01%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on linux/x64Overall (-0.01% to +0.00%)
FullOpts (-0.02% to +0.01%)
Details here |
{ | ||
bool hasProfWeight = true; | ||
|
||
// Inherit first estimate from the exit target; optEstimateEdgeLikelihood | ||
assert(block->GetUniqueSucc() != nullptr); | ||
// Inherit first estimate from the target target; optEstimateEdgeLikelihood |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Inherit first estimate from the target target; optEstimateEdgeLikelihood | |
// Inherit first estimate from the target; optEstimateEdgeLikelihood |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will include this as part of a future PR.
Diff results for #98407Assembly diffsAssembly diffs for linux/arm64 ran on windows/x64Diffs are based on 2,528,537 contexts (1,004,581 MinOpts, 1,523,956 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 14 (0.00%) Overall (-29,788 bytes)
FullOpts (-29,788 bytes)
Assembly diffs for linux/x64 ran on windows/x64Diffs are based on 2,531,978 contexts (984,938 MinOpts, 1,547,040 FullOpts). MISSED contexts: 1 (0.00%) Overall (-39,315 bytes)
FullOpts (-39,315 bytes)
Assembly diffs for osx/arm64 ran on windows/x64Diffs are based on 2,298,749 contexts (931,667 MinOpts, 1,367,082 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 4 (0.00%) Overall (-14,884 bytes)
FullOpts (-14,884 bytes)
Assembly diffs for windows/arm64 ran on windows/x64Diffs are based on 2,380,843 contexts (948,167 MinOpts, 1,432,676 FullOpts). MISSED contexts: base: 0 (0.00%), diff: 9 (0.00%) Overall (+1,588 bytes)
FullOpts (+1,588 bytes)
Assembly diffs for windows/x64 ran on windows/x64Diffs are based on 2,821,026 contexts (1,163,479 MinOpts, 1,657,547 FullOpts). Overall (+30,637 bytes)
FullOpts (+30,637 bytes)
Details here Assembly diffs for linux/arm ran on windows/x86Diffs are based on 2,242,904 contexts (830,244 MinOpts, 1,412,660 FullOpts). MISSED contexts: 73,620 (3.18%) Overall (-3,540 bytes)
FullOpts (-3,540 bytes)
Assembly diffs for windows/x86 ran on windows/x86Diffs are based on 2,599,256 contexts (1,005,474 MinOpts, 1,593,782 FullOpts). MISSED contexts: base: 625 (0.02%), diff: 667 (0.03%) Overall (-5,415 bytes)
FullOpts (-5,415 bytes)
Details here Throughput diffsThroughput diffs for linux/arm64 ran on windows/x64Overall (-0.01% to +0.01%)
MinOpts (-0.01% to +0.00%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on windows/x64Overall (-0.01% to +0.01%)
FullOpts (-0.02% to +0.01%)
Throughput diffs for windows/x64 ran on windows/x64FullOpts (-0.00% to +0.01%)
Details here Throughput diffs for windows/x86 ran on windows/x86Overall (-0.01% to +0.00%)
FullOpts (-0.01% to +0.00%)
Details here Throughput diffs for linux/arm64 ran on linux/x64Overall (-0.01% to +0.01%)
FullOpts (-0.01% to +0.01%)
Throughput diffs for linux/x64 ran on linux/x64Overall (-0.01% to +0.00%)
FullOpts (-0.02% to +0.01%)
Details here |
The preheader/exit weight calculation is essentially the same logic, so unify it to use the logic from the exit weight calculation. This also fixes a bug in the preheader weight calculation introduced by my recent change where we sometimes mistakenly used the weight of the newly inserted preheader instead of the header block to compute a likelihood.
The bug was here:
runtime/src/coreclr/jit/optimizer.cpp
Lines 3075 to 3087 in d464313
The
succ == preheader
case should have computed theloopEnterCount
asloop->GetHeader()->bbWeight
which is what the logic used to do before #96843. Of course this estimate is itself questionable, but better than using the newly inserted preheader's weight, which is always100
.Fix #98370