-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fold constant string null checks #1377
Conversation
Example from #1368 G_M26703_IG01:
56 push rsi
4883EC20 sub rsp, 32
;; bbWeight=1 PerfScore 1.25
G_M26703_IG02:
48B898314E43CE010000 mov rax, 0x1CE434E3198
48833800 cmp gword ptr [rax], 0
740E je SHORT G_M26703_IG06
;; bbWeight=1 PerfScore 3.25
G_M26703_IG03:
4885C9 test rcx, rcx
7442 je SHORT G_M26703_IG07
;; bbWeight=0.50 PerfScore 0.63
G_M26703_IG04:
488BC1 mov rax, rcx
;; bbWeight=1 PerfScore 0.25
G_M26703_IG05:
4883C420 add rsp, 32
5E pop rsi
C3 ret
;; bbWeight=1 PerfScore 1.75
G_M26703_IG06:
48B9C8B9D1A3FA7F0000 mov rcx, 0x7FFAA3D1B9C8
E81E178B5F call CORINFO_HELP_NEWSFAST
… After: G_M26703_IG01:
56 push rsi
4883EC20 sub rsp, 32
;; bbWeight=1 PerfScore 1.25
G_M26703_IG02:
4885C9 test rcx, rcx
7409 je SHORT G_M26703_IG05
;; bbWeight=1 PerfScore 1.25
G_M26703_IG03:
488BC1 mov rax, rcx
;; bbWeight=1 PerfScore 0.25
G_M26703_IG04:
4883C420 add rsp, 32
5E pop rsi
C3 ret
;; bbWeight=1 PerfScore 1.75
G_M26703_IG05:
48B9C8B9D2A3FA7F0000 mov rcx, 0x7FFAA3D2B9C8
E82E178A5F call CORINFO_HELP_NEWSFAST
… |
Diff summary:
The |
Heh, this PR along with #1378 should eliminate |
@mikedn May I ask why you closed this? ReadOnlySpan<char> span = "hello"; currently produces a redundant nullcheck over ldstr. |
GT_CNS_STR
can't ever produce a null value so we can constant fold"str" != null
and similar expressions early, beforeGT_CNS_STR
gets expanded into anIND(GT_CNS_INT)
which is more problematic to recognize as non null.Fixes #1368