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
This PR creates more assertions that can be used by various
optimizations. Minimal examples:
```cs
object Case1(object[] arr, int i, object b)
{
// covariant stores used to be ignored by range check
arr[3] = b; // arr is >= 4 elements long
return arr[2]; // no bounds check anymore
}
bool Case2(int a, int b)
{
int c = a / b;
// b is never 0 here
return b == 0;
}
byte[] Case3(int numBytes, IntPtr pbData)
{
byte[] data = new byte[numBytes];
if (numBytes < 0) // never true
throw new InvalidOperationException();
return data;
}
```
```diff
; Method Examples:Case1(System.Object[],int,System.Object):System.Object:this (FullOpts)
push rbx
sub rsp, 32
mov rbx, rdx
mov rcx, rbx
mov r8, r9
mov edx, 3
call CORINFO_HELP_ARRADDR_ST
- cmp dword ptr [rbx+0x08], 2
- jbe SHORT G_M25522_IG04
mov rax, gword ptr [rbx+0x20]
add rsp, 32
pop rbx
ret
-G_M25522_IG04:
- call CORINFO_HELP_RNGCHKFAIL
- int3
-; Total bytes of code: 46
+; Total bytes of code: 34
; Method Examples:Case2(int,int):bool:this (FullOpts)
mov eax, edx
cdq
idiv edx:eax, r8d
- test r8d, r8d
- sete al
- movzx rax, al
+ xor eax, eax
ret
-; Total bytes of code: 16
+; Total bytes of code: 9
; Method Examples:Case3(int,nint):byte[]:this (FullOpts)
- push rbx
- sub rsp, 32
- mov ebx, edx
- movsxd rdx, ebx
+ sub rsp, 40
+ movsxd rdx, edx
mov rcx, 0x7FFF08D305B8 ; byte[]
call CORINFO_HELP_NEWARR_1_VC
- test ebx, ebx
- jl SHORT G_M3253_IG04
- add rsp, 32
- pop rbx
- ret
-G_M3253_IG04:
- mov rcx, 0x7FFF08D8CB60 ; System.InvalidOperationException
- call CORINFO_HELP_NEWSFAST
- mov rbx, rax
- mov rcx, rbx
- call [System.InvalidOperationException:.ctor():this]
- mov rcx, rbx
- call CORINFO_HELP_THROW
- int3
-; Total bytes of code: 71
+ nop
+ add rsp, 40
+ ret
+; Total bytes of code: 28
```
[diffs](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1304188&view=ms.vss-build-web.run-extensions-tab)
---------
Co-authored-by: egorbot <egorbot@egorbo.com>
0 commit comments