Commit d04703b
authored
Don't give up on folding obj.GetType if obj can be null (#129371)
This PR:
* in vn when we call `gtGetClassHandle` to fold `obj.GetType()` into a
constant (on VN level) we shouldn't give up if `gtGetClassHandle` is
unsure about `obj` being never null
* `gtGetClassHandle` now calls `fgAddrCouldBeNull` and
`vnStore->IsKnownNonNull` for its `isNonNull` out param.
Example:
```cs
string _fld;
Type Foo() => _fld.GetType();
```
Was:
```asm
; Method Proga:Foo():System.Type:this (FullOpts)
sub rsp, 40
mov rcx, gword ptr [rcx+0x08]
call [System.Object:GetType():System.Type:this]
nop
add rsp, 40
ret
```
Now:
```asm
; Method Proga:Foo():System.Type:this (FullOpts)
mov eax, dword ptr [rcx+0x08] ;; nullcheck
mov rax, 0x2BC495400E0 ; 'System.String'
ret
```
[diffs](MihuBot/runtime-utils#1978)1 parent 0080389 commit d04703b
2 files changed
Lines changed: 24 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21022 | 21022 | | |
21023 | 21023 | | |
21024 | 21024 | | |
| 21025 | + | |
| 21026 | + | |
| 21027 | + | |
| 21028 | + | |
| 21029 | + | |
| 21030 | + | |
| 21031 | + | |
| 21032 | + | |
| 21033 | + | |
| 21034 | + | |
| 21035 | + | |
| 21036 | + | |
21025 | 21037 | | |
21026 | 21038 | | |
21027 | 21039 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13707 | 13707 | | |
13708 | 13708 | | |
13709 | 13709 | | |
13710 | | - | |
| 13710 | + | |
13711 | 13711 | | |
13712 | 13712 | | |
13713 | 13713 | | |
13714 | 13714 | | |
13715 | | - | |
13716 | | - | |
| 13715 | + | |
| 13716 | + | |
| 13717 | + | |
| 13718 | + | |
| 13719 | + | |
| 13720 | + | |
| 13721 | + | |
| 13722 | + | |
| 13723 | + | |
| 13724 | + | |
| 13725 | + | |
13717 | 13726 | | |
13718 | 13727 | | |
13719 | 13728 | | |
| |||
0 commit comments