Skip to content

[NativeAOT-LLVM] Investigate why is wasm-opt able to remove so much code #3132

Open
@SingleAccretion

Description

@SingleAccretion

Reproduction is simple, e. g. on the DynamicGeneric.csproj test we see:

./wasmjit-diff -r ..\DynamicGenerics\DynamicGenerics.csproj -p '/p:InvariantGlobalization=true'
./wasmjit-diff -s -b ..\DynamicGenerics\DynamicGenerics.csproj -p '/p:InvariantGlobalization=true /p:EmccExtraArgs=-O2'
Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 3519392
Total bytes of diff: 2982985
Total bytes of delta: -536407 (-15.24% % of base)
Average relative delta: -15.13%
    diff is an improvement
    average relative diff is an improvement

Top method regressions (percentages):
           1 (50.00% of base) : 6924.dasm - DynamicGenerics_Dictionaries_Base___ctor
           1 (50.00% of base) : 6923.dasm - DynamicGenerics_Dictionaries_GenBase_1<System___Canon>___ctor
           1 (50.00% of base) : 6922.dasm - DynamicGenerics_Dictionaries_Gen_1<System___Canon>___ctor
           1 (50.00% of base) : 6911.dasm - DynamicGenerics_Dictionaries_SingleUseArrayOnlyGen_1<System___Canon>___ctor
           1 (50.00% of base) : 6847.dasm - S_P_CoreLib_System_Collections_Generic_HashSet_1_Enumerator<Char>__Dispose
           1 (50.00% of base) : 1419.dasm - WKS::GCHeap::TemporaryEnableConcurrentGC()
           1 (50.00% of base) : 1418.dasm - WKS::GCHeap::DiagGetGCSettings(EtwGCSettingsInfo*)
           1 (50.00% of base) : 6925.dasm - DynamicGenerics_My___ctor
           1 (50.00% of base) : 1420.dasm - WKS::GCHeap::TemporaryDisableConcurrentGC()
           1 (50.00% of base) : 6577.dasm - S_P_CoreLib_System_Buffers_ArrayPoolEventSource___ctor_0
           1 (50.00% of base) : 1573.dasm - GCToOSInterface::FlushProcessWriteBuffers()
           1 (50.00% of base) : 3168.dasm - S_P_CoreLib_System_Threading_ExecutionContext__Dispose
           1 (50.00% of base) : 7172.dasm - S_P_CoreLib_System_Collections_Generic_List_1_Enumerator<S_P_CoreLib_System_Collections_Generic_KeyValuePair_2<System___Canon__Bool>>__Dispose
           1 (50.00% of base) : 7176.dasm - S_P_CoreLib_System_Collections_Generic_List_1_Enumerator<S_P_CoreLib_System_Collections_Generic_KeyValuePair_2<System___Canon__Int32>>__Dispose
           1 (50.00% of base) : 7174.dasm - S_P_CoreLib_System_Collections_Generic_Dictionary_2_KeyCollection_Enumerator<System___Canon__Bool>__Dispose
           1 (50.00% of base) : 7175.dasm - S_P_CoreLib_System_Collections_Generic_Dictionary_2_Enumerator<System___Canon__Bool>__Dispose
           1 (50.00% of base) : 11754.dasm - S_P_CoreLib_System_Runtime_InteropServices_InAttribute___ctor
           1 (50.00% of base) : 7177.dasm - S_P_CoreLib_System_Collections_Generic_Dictionary_2_ValueCollection_Enumerator<System___Canon__Int32>__Dispose
           1 (50.00% of base) : 7178.dasm - S_P_CoreLib_System_Collections_Generic_Dictionary_2_KeyCollection_Enumerator<System___Canon__Int32>__Dispose
           1 (50.00% of base) : 7179.dasm - S_P_CoreLib_System_Collections_Generic_Dictionary_2_Enumerator<System___Canon__Int32>__Dispose

Top methods only present in diff:
          18 (     ∞ of base) : 13819.dasm - __bswap_16.1
           5 (     ∞ of base) : 13817.dasm - __DOUBLE_BITS.1
          21 (     ∞ of base) : 13816.dasm - fp_barrier.1
           3 (     ∞ of base) : 13815.dasm - dummy.2
           4 (     ∞ of base) : 13814.dasm - dummy.1
          42 (     ∞ of base) : 13813.dasm - CheckPromoted(Object**, unsigned long*, unsigned long, unsigned long).1
          24 (     ∞ of base) : 13812.dasm - GCHandleStore::~GCHandleStore().1
           5 (     ∞ of base) : 13818.dasm - __cxx_global_array_dtor.1

Top method improvements (percentages):
         -82 (-94.25% of base) : 13792.dasm - abort_message
         -44 (-66.67% of base) : 1586.dasm - PalGetMaximumStackBounds_SingleThreadedWasm(void**, void**)
          -8 (-57.14% of base) : 1128.dasm - GetThreadStore()
         -87 (-56.49% of base) : 3338.dasm - S_P_CoreLib_System_Threading_ManualResetEventSlim__UpdateStateAtomically
          -4 (-50.00% of base) : 13805.dasm - stackSave
          -4 (-50.00% of base) : 1102.dasm - SyncClean::CleanUp()
          -4 (-50.00% of base) : 1591.dasm - InitializeGCSelector()
          -4 (-50.00% of base) : 1526.dasm - GetCurrentThreadAllocContext()
        -144 (-49.15% of base) : 7862.dasm - S_P_CoreLib_System_Exception__ReportAllFramesAsJS
          -7 (-46.67% of base) : 1531.dasm - RaiseFailFastException
          -4 (-44.44% of base) : 1603.dasm - SystemNative_Abort
         -37 (-44.05% of base) : 1001.dasm - main
          -7 (-43.75% of base) : 13726.dasm - sched_yield
          -5 (-41.67% of base) : 1114.dasm - RhGetThreadStaticStorage
          -4 (-40.00% of base) : 1048.dasm - GCToEEInterface::RefCountedHandleCallbacks(Object*)
          -8 (-40.00% of base) : 1123.dasm - RhpGetModuleSection
          -4 (-40.00% of base) : 2663.dasm - RhpThrowNativeException
          -4 (-40.00% of base) : 13806.dasm - stackRestore
          -7 (-38.89% of base) : 1433.dasm - GCScan::GcWeakPtrScanBySingleThread(int, int, ScanContext*)
          -7 (-38.89% of base) : 1428.dasm - GCScan::GetGcRuntimeStructuresValid()

Top methods only present in base:
         -54 (-100.00% of base) : 7748.dasm - S_P_CoreLib_System_Runtime_EH__ThrowClasslibOverflowException
          -7 (-100.00% of base) : 2644.dasm - RhpGetLastPreciseVirtualUnwindFrame
        -451 (-100.00% of base) : 7730.dasm - S_P_CoreLib_System_Runtime_RuntimeExports__RhUnboxAny
         -92 (-100.00% of base) : 12289.dasm - S_P_CoreLib_Internal_TypeSystem_LockFreeReaderHashtableOfPointers_2<System___Canon__S_P_CoreLib_System_Runtime_InteropServices_GCHandle>__TryWriteSentinelToLocation
          -5 (-100.00% of base) : 13761.dasm - __DOUBLE_BITS*
          -9 (-100.00% of base) : 2645.dasm - RhpCallCatchFunclet
         -48 (-100.00% of base) : 1503.dasm - CheckPromoted(Object**, unsigned long*, unsigned long, unsigned long)*
          -9 (-100.00% of base) : 2646.dasm - RhpCallFilterFunclet
        -155 (-100.00% of base) : 6467.dasm - S_P_CoreLib_System_Random_XoshiroImpl__Next
          -9 (-100.00% of base) : 2647.dasm - RhpCallFinallyFunclet
        -292 (-100.00% of base) : 4001.dasm - S_P_CoreLib_Internal_IntrinsicSupport_EqualityComparerHelpers__StructOnlyEquals<S_P_CoreLib_System_Collections_Concurrent_ConcurrentUnifierWKeyed_2_Entry<S_P_CoreLib_System_Reflection_Runtime_TypeInfos_NativeFormat_NativeFormatRuntimeGenericParameterTypeInfoForMethods_UnificationKey__System___Canon>>
         -29 (-100.00% of base) : 4002.dasm - S_P_CoreLib_Internal_IntrinsicSupport_EqualityComparerHelpers__GetComparerForReferenceTypesOnly<S_P_CoreLib_System_Collections_Concurrent_ConcurrentUnifierWKeyed_2_Entry<S_P_CoreLib_System_Reflection_Runtime_TypeInfos_NativeFormat_NativeFormatRuntimeGenericParameterTypeInfoForMethods_UnificationKey__System___Canon>>
        -258 (-100.00% of base) : 2650.dasm - StackFrameIterator::CalculateCurrentMethodState()
        -392 (-100.00% of base) : 2651.dasm - StackFrameIterator::InternalInitForStackTrace()
        -109 (-100.00% of base) : 12288.dasm - S_P_CoreLib_Internal_TypeSystem_LockFreeReaderHashtableOfPointers_2<System___Canon__S_P_CoreLib_System_Runtime_InteropServices_GCHandle>__VolatileReadNonSentinelFromHashtable
        -163 (-100.00% of base) : 4004.dasm - S_P_CoreLib_System_Array__IndexOf_4<S_P_CoreLib_System_Collections_Concurrent_ConcurrentUnifierWKeyed_2_Entry<S_P_CoreLib_System_Reflection_Runtime_TypeInfos_NativeFormat_NativeFormatRuntimeGenericParameterTypeInfoForMethods_UnificationKey__System___Canon>>
        -173 (-100.00% of base) : 13078.dasm - S_P_CoreLib_System_Array__IndexOf_4<UInt8>
        -170 (-100.00% of base) : 11611.dasm - S_P_TypeLoader_Internal_TypeSystem_ExceptionTypeNameFormatter__GetTypeName
        -100 (-100.00% of base) : 7733.dasm - S_P_CoreLib_System_Runtime_InternalCalls__RhEndNoGCRegion
        -113 (-100.00% of base) : 12086.dasm - S_P_CoreLib_System_Threading_Thread__StopThread

12820 total methods with Code Size differences (12533 improved, 287 regressed)

The starting point would be to check how much of this is due to stack trace data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-LLVMLLVM generation for Native AOT compilation (including Web Assembly)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions