Commit 87b69c5
authored
JIT: Expand recognition of struct field offset pattern (#122297)
The JIT has an optimization to recognize recomputations of field
offsets, but this optimization failed to trigger in certain cases when
the struct was promoted with old promotion.
```csharp
public unsafe nint Test()
{
MyStruct dummy;
return (nint)((byte*)&dummy.Field - (byte*)&dummy);
}
private struct MyStruct
{
public int A;
public int Field;
}
```
Before:
```asm
G_M27992_IG01: ;; offset=0x0000
push rax
xor eax, eax
mov qword ptr [rsp], rax
;; size=7 bbWeight=1 PerfScore 2.25
G_M27992_IG02: ;; offset=0x0007
lea rax, [rsp+0x04]
lea rcx, [rsp]
sub rax, rcx
;; size=12 bbWeight=1 PerfScore 1.25
G_M27992_IG03: ;; offset=0x0013
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
```
After:
```asm
G_M27992_IG02: ;; offset=0x0000
mov eax, 4
;; size=5 bbWeight=1 PerfScore 0.25
G_M27992_IG03: ;; offset=0x0005
ret
;; size=1 bbWeight=1 PerfScore 1.00
```1 parent 15663b5 commit 87b69c5
1 file changed
Lines changed: 35 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1142 | 1142 | | |
1143 | 1143 | | |
1144 | 1144 | | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1145 | + | |
1148 | 1146 | | |
1149 | | - | |
1150 | | - | |
| 1147 | + | |
| 1148 | + | |
1151 | 1149 | | |
1152 | | - | |
1153 | | - | |
1154 | | - | |
1155 | | - | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
1160 | 1182 | | |
1161 | 1183 | | |
1162 | 1184 | | |
| |||
0 commit comments