Commit b1cd0f4
authored
JIT: Support bitwise field extractions from parameter registers (dotnet#112740)
Recent work now allows us to finally add support for the backend to
extract fields out of parameters without spilling them to stack.
Previously this was only supported when the fields mapped cleanly to
registers.
A win-x64 example:
```csharp
static int Foo(int? foo)
{
return foo.HasValue ? foo.Value : 0;
}
```
```diff
; Method Program:Foo(System.Nullable`1[int]):int (FullOpts)
G_M19236_IG01: ;; offset=0x0000
- mov qword ptr [rsp+0x08], rcx
- ;; size=5 bbWeight=0.50 PerfScore 0.50
+ ;; size=0 bbWeight=0.50 PerfScore 0.00
-G_M19236_IG02: ;; offset=0x0005
- movzx rcx, cl
- xor eax, eax
- test ecx, ecx
- cmovne eax, dword ptr [rsp+0x0C]
- ;; size=12 bbWeight=0.50 PerfScore 1.38
+G_M19236_IG02: ;; offset=0x0000
+ movzx rax, cl
+ shr rcx, 32
+ xor edx, edx
+ test eax, eax
+ mov eax, edx
+ cmovne eax, ecx
+ ;; size=16 bbWeight=0.50 PerfScore 0.88
-G_M19236_IG03: ;; offset=0x0011
+G_M19236_IG03: ;; offset=0x0010
ret
;; size=1 bbWeight=0.50 PerfScore 0.50
-; Total bytes of code: 18
-
+; Total bytes of code: 17
```
Another win-x64 example:
```csharp
static float Sum(PointF p)
{
return p.X + p.Y;
}
```
```diff
; Method Program:Sum(System.Drawing.PointF):float (FullOpts)
G_M48891_IG01: ;; offset=0x0000
- mov qword ptr [rsp+0x08], rcx
- ;; size=5 bbWeight=1 PerfScore 1.00
+ ;; size=0 bbWeight=1 PerfScore 0.00
-G_M48891_IG02: ;; offset=0x0005
- vmovss xmm0, dword ptr [rsp+0x08]
- vaddss xmm0, xmm0, dword ptr [rsp+0x0C]
- ;; size=12 bbWeight=1 PerfScore 8.00
+G_M48891_IG02: ;; offset=0x0000
+ vmovd xmm0, ecx
+ shr rcx, 32
+ vmovd xmm1, ecx
+ vaddss xmm0, xmm0, xmm1
+ ;; size=16 bbWeight=1 PerfScore 7.50
-G_M48891_IG03: ;; offset=0x0011
+G_M48891_IG03: ;; offset=0x0010
ret
;; size=1 bbWeight=1 PerfScore 1.00
-; Total bytes of code: 18
+; Total bytes of code: 17
```
An arm64 example:
```csharp
static bool Test(Memory<int> mem)
{
return mem.Length > 10;
}
```
```diff
; Method Program:Test(System.Memory`1[int]):ubyte (FullOpts)
G_M53448_IG01: ;; offset=0x0000
- stp fp, lr, [sp, #-0x20]!
+ stp fp, lr, [sp, #-0x10]!
mov fp, sp
- stp x0, x1, [fp, #0x10] // [V00 arg0], [V00 arg0+0x08]
- ;; size=12 bbWeight=1 PerfScore 2.50
+ ;; size=8 bbWeight=1 PerfScore 1.50
-G_M53448_IG02: ;; offset=0x000C
- ldr w0, [fp, #0x1C] // [V00 arg0+0x0c]
+G_M53448_IG02: ;; offset=0x0008
+ lsr x0, x1, dotnet#32
cmp w0, #10
cset x0, gt
- ;; size=12 bbWeight=1 PerfScore 3.00
+ ;; size=12 bbWeight=1 PerfScore 2.00
-G_M53448_IG03: ;; offset=0x0018
- ldp fp, lr, [sp], #0x20
+G_M53448_IG03: ;; offset=0x0014
+ ldp fp, lr, [sp], #0x10
ret lr
;; size=8 bbWeight=1 PerfScore 2.00
-; Total bytes of code: 32
+; Total bytes of code: 28
```
Float -> float extractions that do not map cleanly is still not supported, but
should be doable (via vector register extractions). Float -> int extractions are
not supported, but I'm not sure we see these.
This is often not a code size improvement, but typically a perfscore
improvement. Also this seems to have some bad interactions with call arguments
since they do not yet support something similar, but hopefully that can be
improved separately.1 parent fde7c8f commit b1cd0f4
2 files changed
Lines changed: 108 additions & 89 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8379 | 8379 | | |
8380 | 8380 | | |
8381 | 8381 | | |
8382 | | - | |
8383 | | - | |
8384 | | - | |
8385 | | - | |
8386 | | - | |
8387 | | - | |
8388 | | - | |
8389 | | - | |
8390 | | - | |
8391 | | - | |
8392 | | - | |
8393 | | - | |
8394 | | - | |
8395 | | - | |
8396 | | - | |
8397 | | - | |
8398 | | - | |
8399 | | - | |
8400 | | - | |
8401 | | - | |
8402 | | - | |
8403 | | - | |
8404 | | - | |
8405 | | - | |
8406 | | - | |
8407 | | - | |
8408 | | - | |
8409 | | - | |
8410 | 8382 | | |
8411 | 8383 | | |
8412 | 8384 | | |
| |||
8706 | 8678 | | |
8707 | 8679 | | |
8708 | 8680 | | |
8709 | | - | |
8710 | | - | |
| 8681 | + | |
| 8682 | + | |
8711 | 8683 | | |
8712 | 8684 | | |
8713 | 8685 | | |
8714 | 8686 | | |
8715 | | - | |
8716 | | - | |
8717 | | - | |
8718 | | - | |
| 8687 | + | |
| 8688 | + | |
| 8689 | + | |
| 8690 | + | |
8719 | 8691 | | |
8720 | | - | |
| 8692 | + | |
8721 | 8693 | | |
8722 | 8694 | | |
| 8695 | + | |
| 8696 | + | |
8723 | 8697 | | |
8724 | 8698 | | |
8725 | 8699 | | |
| |||
8728 | 8702 | | |
8729 | 8703 | | |
8730 | 8704 | | |
8731 | | - | |
| 8705 | + | |
8732 | 8706 | | |
8733 | 8707 | | |
8734 | 8708 | | |
| |||
8742 | 8716 | | |
8743 | 8717 | | |
8744 | 8718 | | |
8745 | | - | |
| 8719 | + | |
| 8720 | + | |
8746 | 8721 | | |
8747 | | - | |
| 8722 | + | |
| 8723 | + | |
8748 | 8724 | | |
8749 | | - | |
8750 | | - | |
8751 | | - | |
8752 | | - | |
8753 | | - | |
| 8725 | + | |
| 8726 | + | |
| 8727 | + | |
| 8728 | + | |
| 8729 | + | |
| 8730 | + | |
| 8731 | + | |
| 8732 | + | |
| 8733 | + | |
8754 | 8734 | | |
8755 | | - | |
8756 | | - | |
| 8735 | + | |
8757 | 8736 | | |
8758 | 8737 | | |
8759 | | - | |
8760 | | - | |
8761 | | - | |
| 8738 | + | |
| 8739 | + | |
8762 | 8740 | | |
| 8741 | + | |
| 8742 | + | |
| 8743 | + | |
| 8744 | + | |
| 8745 | + | |
| 8746 | + | |
| 8747 | + | |
8763 | 8748 | | |
8764 | 8749 | | |
8765 | 8750 | | |
8766 | | - | |
8767 | | - | |
8768 | | - | |
| 8751 | + | |
| 8752 | + | |
8769 | 8753 | | |
8770 | | - | |
8771 | | - | |
8772 | | - | |
| 8754 | + | |
8773 | 8755 | | |
8774 | | - | |
8775 | | - | |
8776 | | - | |
8777 | | - | |
8778 | | - | |
8779 | | - | |
| 8756 | + | |
| 8757 | + | |
| 8758 | + | |
| 8759 | + | |
| 8760 | + | |
| 8761 | + | |
| 8762 | + | |
| 8763 | + | |
| 8764 | + | |
| 8765 | + | |
| 8766 | + | |
| 8767 | + | |
| 8768 | + | |
| 8769 | + | |
8780 | 8770 | | |
8781 | 8771 | | |
| 8772 | + | |
| 8773 | + | |
| 8774 | + | |
8782 | 8775 | | |
8783 | | - | |
8784 | | - | |
| 8776 | + | |
| 8777 | + | |
| 8778 | + | |
| 8779 | + | |
| 8780 | + | |
| 8781 | + | |
| 8782 | + | |
8785 | 8783 | | |
8786 | | - | |
8787 | | - | |
8788 | | - | |
| 8784 | + | |
| 8785 | + | |
| 8786 | + | |
| 8787 | + | |
| 8788 | + | |
| 8789 | + | |
| 8790 | + | |
8789 | 8791 | | |
8790 | | - | |
8791 | | - | |
8792 | | - | |
8793 | | - | |
8794 | | - | |
8795 | | - | |
8796 | | - | |
8797 | | - | |
| 8792 | + | |
| 8793 | + | |
| 8794 | + | |
| 8795 | + | |
| 8796 | + | |
8798 | 8797 | | |
8799 | | - | |
8800 | | - | |
8801 | | - | |
| 8798 | + | |
| 8799 | + | |
| 8800 | + | |
| 8801 | + | |
| 8802 | + | |
| 8803 | + | |
| 8804 | + | |
| 8805 | + | |
| 8806 | + | |
| 8807 | + | |
8802 | 8808 | | |
8803 | | - | |
8804 | | - | |
8805 | | - | |
8806 | | - | |
8807 | | - | |
8808 | | - | |
8809 | | - | |
8810 | | - | |
8811 | | - | |
8812 | | - | |
| 8809 | + | |
| 8810 | + | |
| 8811 | + | |
| 8812 | + | |
| 8813 | + | |
8813 | 8814 | | |
8814 | 8815 | | |
| 8816 | + | |
| 8817 | + | |
| 8818 | + | |
| 8819 | + | |
| 8820 | + | |
| 8821 | + | |
8815 | 8822 | | |
8816 | 8823 | | |
8817 | 8824 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3053 | 3053 | | |
3054 | 3054 | | |
3055 | 3055 | | |
3056 | | - | |
3057 | | - | |
| 3056 | + | |
| 3057 | + | |
3058 | 3058 | | |
3059 | | - | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
3060 | 3065 | | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
3061 | 3073 | | |
3062 | 3074 | | |
3063 | 3075 | | |
| |||
0 commit comments