-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
Would it make sense for the JITer to eliminate redundant "if null then throw" (i.e. if (arg == null) throw Exception();
) checks for a given argument if it is not possible for that argument value to have changed between the checks? As far as I can tell this does not currently happen, even for simple cases.
For example:
void M1(string value) => M2(value ?? throw new ArgumentNullException();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void M2(string value) => M3(value ?? throw new ArgumentNullException();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void M3(string value) => M4(value ?? throw new ArgumentNullException();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void M4(string value)
{
if (value == null)
throw new ArgumentNullException();
}
// After inlining M1 effectively becomes:
void M1(string value)
{
if (value == null) throw new ArgumentNullException();
// These can be removed:
if (value == null) throw new ArgumentNullException();
if (value == null) throw new ArgumentNullException();
if (value == null) throw new ArgumentNullException();
}
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI