dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.2k stars 4.72k forks source link

[Perf] Regression in floating point math tests #49158

Open DrewScoggins opened 3 years ago

DrewScoggins commented 3 years ago

Run Information

Architecture x64
OS ubuntu 18.04
Baseline ee3f7daed083477689a4c6240025afa45ffa3352
Compare e093fe0fa650d17ec34e944f2a4a9bd2f2700109

Regressions in System.MathBenchmarks.Double

Benchmark Baseline Test Test/Base Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
[Max](<https://pvscmdupload.blob.core.windows.net/reports/allTestHistory/refs/heads/master_x64_ubuntu 18.04/System.MathBenchmarks.Double.Max.html>) 5.45 μs 6.53 μs 1.20

graph Historical Data in Reporting System

Repro

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'System.MathBenchmarks.Double*'
. ### Payloads [Baseline]() [Compare]() ### Histogram #### System.MathBenchmarks.Double.Max ```log [5347.644 ; 5547.693) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [5547.693 ; 5805.447) | @@ [5805.447 ; 5991.886) | [5991.886 ; 6113.254) | [6113.254 ; 6299.693) | @@@@@@ [6299.693 ; 6561.623) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ``` ### Docs [Profiling workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/profiling-workflow-dotnet-runtime.md) [Benchmarking workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/benchmarking-workflow-dotnet-runtime.md)

Run Information

Architecture x64
OS ubuntu 18.04
Baseline ee3f7daed083477689a4c6240025afa45ffa3352
Compare e093fe0fa650d17ec34e944f2a4a9bd2f2700109

Regressions in SciMark2.kernel

Benchmark Baseline Test Test/Base Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
[benchFFT](<https://pvscmdupload.blob.core.windows.net/reports/allTestHistory/refs/heads/master_x64_ubuntu 18.04/SciMark2.kernel.benchFFT.html>) 658.41 ms 698.96 ms 1.06

graph Historical Data in Reporting System

Repro

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'SciMark2.kernel*'
. ### Payloads [Baseline]() [Compare]() ### Histogram #### SciMark2.kernel.benchFFT ```log [655729448.035 ; 676663647.642) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [676663647.642 ; 692503807.843) | @@@@ [692503807.843 ; 717552396.489) | @@@@@@@@@@@@@@@ ``` ### Docs [Profiling workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/profiling-workflow-dotnet-runtime.md) [Benchmarking workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/benchmarking-workflow-dotnet-runtime.md)

Run Information

Architecture x64
OS ubuntu 18.04
Baseline ee3f7daed083477689a4c6240025afa45ffa3352
Compare e093fe0fa650d17ec34e944f2a4a9bd2f2700109

Regressions in System.MathBenchmarks.Single

Benchmark Baseline Test Test/Base Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
[Log2](<https://pvscmdupload.blob.core.windows.net/reports/allTestHistory/refs/heads/master_x64_ubuntu 18.04/System.MathBenchmarks.Single.Log2.html>) 18.51 μs 21.75 μs 1.18
[Exp](<https://pvscmdupload.blob.core.windows.net/reports/allTestHistory/refs/heads/master_x64_ubuntu 18.04/System.MathBenchmarks.Single.Exp.html>) 22.84 μs 25.08 μs 1.10

graph graph Historical Data in Reporting System

Repro

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'System.MathBenchmarks.Single*'
. ### Payloads [Baseline]() [Compare]() ### Histogram #### System.MathBenchmarks.Single.Log2 ```log [18412.486 ; 19092.571) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [19092.571 ; 19487.627) | @ [19487.627 ; 19910.370) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [19910.370 ; 20523.385) | @@@@ [20523.385 ; 21025.635) | [21025.635 ; 21946.489) | @@@@@@@@@@@@ ``` #### System.MathBenchmarks.Single.Exp ```log [22217.514 ; 22720.791) | @@@@@@@@@@@@@@@@@@@@@@@@@@ [22720.791 ; 23284.947) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [23284.947 ; 23819.070) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [23819.070 ; 24554.329) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [24554.329 ; 25305.906) | @@@@@@@@@@@@@@@@@ [25305.906 ; 25858.418) | [25858.418 ; 26410.931) | [26410.931 ; 27038.848) | [27038.848 ; 27585.087) | @ [27585.087 ; 28137.600) | [28137.600 ; 28690.112) | [28690.112 ; 29481.753) | @ ``` ### Docs [Profiling workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/profiling-workflow-dotnet-runtime.md) [Benchmarking workflow for dotnet/runtime repository](https://github.com/dotnet/performance/blob/master/docs/benchmarking-workflow-dotnet-runtime.md)
dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

DrewScoggins commented 3 years ago

Suspect that this change, https://github.com/dotnet/runtime/pull/44419, is the culprit. cc @briansull

EgorBo commented 3 years ago

I suspect CSE led to spills here. Example:

static double MaxTest()
{
    double x = 0;
    for (int i = 0; i < 5000; i++)
        x += 0.0004;
    return x ;
}

Before we enabled CSE for floats:

G_M17817_IG01:
       vzeroupper 
                        ;; bbWeight=1    PerfScore 1.00
G_M17817_IG02:
       vxorps   xmm0, xmm0
       xor      eax, eax
       align    [0 bytes]
                        ;; bbWeight=1    PerfScore 0.83
G_M17817_IG03:
       vaddsd   xmm0, xmm0, qword ptr [reloc @RWD00]
       inc      eax
       cmp      eax, 0x1388
       jl       SHORT G_M17817_IG03
                        ;; bbWeight=4    PerfScore 26.00
G_M17817_IG04:
       ret      
                        ;; bbWeight=1    PerfScore 1.00
RWD00   dq  3F3A36E2EB1C432Dh   ;       0.0004

After:

G_M17817_IG01:
       vzeroupper 
                        ;; bbWeight=1    PerfScore 1.00
G_M17817_IG02:
       vxorps   xmm0, xmm0
       xor      eax, eax
+      vmovsd   xmm1, qword ptr [reloc @RWD00]
       align    [13 bytes]
                        ;; bbWeight=1    PerfScore 2.83
G_M17817_IG03:
-      vaddsd   xmm0, xmm0, qword ptr [reloc @RWD00]
+      vaddsd   xmm0, xmm0, xmm1
       inc      eax
       cmp      eax, 0x1388
       jl       SHORT G_M17817_IG03
                        ;; bbWeight=4    PerfScore 18.00
G_M17817_IG04:
       ret      
                        ;; bbWeight=1    PerfScore 1.00
RWD00   dq  3F3A36E2EB1C432Dh   ;       0.0004

More registers are involved. In this case it's OK, but when we have a lot of locals it leads to spills

briansull commented 3 years ago

Yes, with CSE there is always a trade off involved. So we will get some wins and a few losses.