-
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
cmove is not emitted for a simple expression #90017
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailsint foo(bool cond, int a, int b) => 1 + (cond ? a : b); // or e.g. "cond ? 1 : 2" Current codegen: ; Method Program:foo(bool,int,int):int:this (FullOpts)
test dl, dl
jne SHORT G_M62184_IG04
mov eax, r9d
jmp SHORT G_M62184_IG05
G_M62184_IG04: ;; offset=0x0009
mov eax, r8d
G_M62184_IG05: ;; offset=0x000C
inc eax
ret
; Total bytes of code: 15 Expected: branchless code (cmove) cc @jakobbotsch @dotnet/jit-contrib
|
Works if I move int foo(bool cond, int a, int b) => (cond ? a : b) + 1; ; Method Program:foo(bool,int,int):int:this (FullOpts)
test dl, dl
cmove r8d, r9d
mov eax, r8d
inc eax
ret
; Total bytes of code: 12 |
Likely a separate issue, but as we discussed offline, it'd also be nice if: int foo(bool cond, int a, int b) => (cond ? 1 : 2) + 1; could become the equivalent of: G_M000_IG02:
mov eax, 2
mov edx, 3
test cl, cl
cmove eax, edx
G_M000_IG03:
ret instead of: G_M000_IG02:
mov eax, 1
mov edx, 2
test cl, cl
cmove eax, edx
inc eax
G_M000_IG03:
ret |
This is presumably the same underlying issue as #87072, where Roslyn leaves things on the IL stack across control flow. I'm not at my PC, but I would guess that in this case that introduces additional stores in each basic block that disqualifies it from if conversion. If that's right then we can likely teach if conversion about some of these cases, but it might fit better as an additional opportunity handled by tail merging. |
It might be worth it to invoke forward sub on the new statements created by if-conversion, and then run a folding pass over potentially resulting combined trees. For example, it would optimize It would require a bit of work to make forward sub work with the node threading we have at the point of if-conversion. |
Add a pass that does head merging to compliment the existing tail merging pass. Unlike tail merging this requires reordering the first statement with the terminator node of the predecessor, which requires some interference checking. Fix dotnet#90017
…nsformation (#90468) Add a pass that does head merging to compliment the existing tail merging pass. Unlike tail merging this requires reordering the first statement with the terminator node of the predecessor, which requires some interference checking. The head merging is enabled only for BBJ_COND since the CQ benefit for enabling it more generally does not seem to pay off. Additionally we mainly try to target the IR produced by the importer due to spill cliques, which usually happen with the IL that results from using ternaries. Fix #90017
Current codegen:
Expected: branchless code (cmove)
cc @jakobbotsch @dotnet/jit-contrib
The text was updated successfully, but these errors were encountered: