-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
JIT: simple range check is not branchless #96819
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailsbool IsInRange(int value, int lower, int upper) =>
value >= lower && value <= upper; Current arm64 codegen: ; Method Program:IsInRange(int,int,int):ubyte:this (FullOpts)
G_M32893_IG01: ;; offset=0x0000
stp fp, lr, [sp, #-0x10]!
mov fp, sp
G_M32893_IG02: ;; offset=0x0008
cmp w1, w2
blt G_M32893_IG05
G_M32893_IG03: ;; offset=0x0010
cmp w1, w3
cset x0, le
G_M32893_IG04: ;; offset=0x0018
ldp fp, lr, [sp], #0x10
ret lr
G_M32893_IG05: ;; offset=0x0020
mov w0, wzr
G_M32893_IG06: ;; offset=0x0024
ldp fp, lr, [sp], #0x10
ret lr
; Total bytes of code: 44 Expected codgen: G_M32893_IG01: ;; offset=0x0000
stp fp, lr, [sp, #-0x10]!
mov fp, sp
G_M32893_IG02: ;; offset=0x0008
cmp w1, w2
ccmp w1, w3, #0, ge
cset w1, le
ret
G_M32893_IG06: ;; offset=0x0024
ldp fp, lr, [sp], #0x10
ret lr (based on https://godbolt.org/z/oqjfMPosj) cc @jakobbotsch @dotnet/jit-contrib
|
Ah, I presume it's void IsInRange(int value, int lower, int upper)
{
if (value >= lower && value <= upper)
Console.WriteLine();
} works as expected |
cc @a74nh |
Note that the handling of conversion from short circuiting to bitwise ops is done inside "optimize bools" phase, in @a74nh are you interested in working on it? |
Right, should be similar to the if conversion code.
Yes, but not in the immediate future as there is a lot of SVE work to do. |
Seems like we should move this one out of .NET 9? |
Agreed. We're not going to get to this in time. |
Current arm64 codegen:
Expected codgen:
(based on https://godbolt.org/z/oqjfMPosj)
cc @jakobbotsch @dotnet/jit-contrib
The text was updated successfully, but these errors were encountered: