dotnet/runtime

[JIT] Bool optimization case

Open

#80,966 opened on 2023年1月21日

GitHub で見る
 (2 comments) (1 reaction) (0 assignees)C# (5,445 forks)batch import
area-CodeGen-coreclrhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

    public static void TestBoolAsg(int a, int b, int c, ref bool z)
    {
        z = a == 0 && b == 0 && c == 0;
    }

When comparing the JIT output to this:

    public static bool TestBoolReturn(int a, int b, int c)
    {
        return a == 0 && b == 0 && c == 0;
    }

TestBoolAsg is as not as optimized as TestBoolReturn:

// TestBoolAsg
G_M56616_IG02:              ;; offset=0000H
       0BD1                 or       edx, ecx
       750A                 jne      SHORT G_M56616_IG04
						;; size=4 bbWeight=1 PerfScore 1.25

G_M56616_IG03:              ;; offset=0004H
       33C0                 xor      eax, eax
       4585C0               test     r8d, r8d
       0F94C0               sete     al
       EB02                 jmp      SHORT G_M56616_IG05
						;; size=10 bbWeight=0.50 PerfScore 1.75

G_M56616_IG04:              ;; offset=000EH
       33C0                 xor      eax, eax
						;; size=2 bbWeight=0.50 PerfScore 0.12

G_M56616_IG05:              ;; offset=0010H
       418801               mov      byte  ptr [r9], al
						;; size=3 bbWeight=1 PerfScore 1.00

G_M56616_IG06:              ;; offset=0013H
       C3                   ret   

vs.

// TestBoolReturn
G_M58330_IG02:              ;; offset=0000H
       0BD1                 or       edx, ecx
       410BD0               or       edx, r8d
       0F94C0               sete     al
       0FB6C0               movzx    rax, al
						;; size=11 bbWeight=1 PerfScore 1.75

G_M58330_IG03:              ;; offset=000BH
       C3                   ret 

コントリビューターガイド